Pitel
09/13/2021, 1:25 PMkotlinc
directly from command line?tim
09/13/2021, 3:50 PMgradle.build.kts
file and the duplication is driving us crazy! To start I'd like to extract common dependencies + versions and so we are looking at gradle's version catalogues. But now that we've gone down this route, there are lots of other common blocks in our gradle.build.kts
that we'd like to capture centrally as well for example the plugins block or settings like tasks.withType<KotlinCompile>.kotlinOptions { freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" }
.
So what does best practice look like here? 🙏elect
09/14/2021, 2:46 PMkotlin-bom:1.5.10
relies on stdlib:1.4.21
?
[INFO] +- org.jetbrains.kotlin:kotlin-bom:pom:1.5.10:compile
[INFO] +- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.5.10:compile
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.4.21:compile
[INFO] | | \- org.jetbrains:annotations:jar:13.0:compile
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.5.10:compile
Gabriel Duncan
09/14/2021, 5:37 PMoletjens
09/16/2021, 9:53 AMHenning B
09/16/2021, 2:42 PMw: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
.gradle/caches/transforms-3/59efbb5d2fb40235871696f9259a7d8d/transformed/jetified-kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
.gradle/caches/transforms-3/e66f57a2a74abdb19022465647f40d82/transformed/jetified-kotlin-stdlib-jdk7-1.5.30.jar (version 1.5)
.gradle/caches/transforms-3/2d4b2907d0729a36c30c280633903ab8/transformed/jetified-kotlin-reflect-1.4.10.jar (version 1.4)
.gradle/caches/transforms-3/ef7b524e21c54733be325fc195aa1b28/transformed/jetified-kotlin-stdlib-1.5.30.jar (version 1.5)
.gradle/caches/transforms-3/fa4d08380a08dd9897606270ef087751/transformed/jetified-kotlin-stdlib-common-1.5.30.jar (version 1.5)
William Reed
09/16/2021, 8:28 PM./gradlew wrapper --gradle-version 7.0.2
) and my kotlin gradle scripts show many errors saying something similar to
Cannot access 'kotlin.collections.Collection' which is a supertype of 'org.gradle.api.artifacts.dsl.RepositoryHandler'. Check your module classpath for missing or conflicting dependencies
i don’t see any reason this should happen based on the gradle 7 docs. any ideas?Deepak Gahlot
09/17/2021, 5:58 PMExerosis
09/20/2021, 3:46 PMMichal Klimczak
09/22/2021, 7:19 AM//using just String
myPlugin {
foo = "bar"
}
//using Property
myPlugin {
foo.set("bar")
}
William Reed
09/22/2021, 3:15 PMamadeu01
09/22/2021, 7:57 PM.gradle.kts
file inside a .gradle
file?Ben Madore
09/23/2021, 5:02 PMkotlin-conventions
plugin (precompiled script plugin), that users can put on their app, and it will configure kotlin (apply various plugins, imports kotlin bom, configure detekt etc.)
the version of the kotlin bom applied is configurable via an extension class, but i’ve run into an issue with kapt.
the version of the kotlin plugins (e.g. kapt) applied seems to be fixed, by whatever is added to the plugin build’s classpath.
Is there any way to make this configurable? It looks like using kotlin 1.5.31 at runtime, with kapt plugin version 1.4.31 was causing some very strange and unexpected failures. and i’m not sure how to solve this for a generic plugin.
i guess the generic question is: is there any way to apply a plugin to a project, where the version of the plugin comes from an extension object, and is not statically defined.tim
09/28/2021, 12:45 PM./gradlew tasks
locally:
* What went wrong:
Failed to apply plugin class 'Build_gradle$FooPlugin'.
> Could not create plugin of type 'FooPlugin'.
> The constructor for type Build_gradle.FooPlugin should be annotated with @Inject.
Łukasz Kłosiński
09/29/2021, 1:55 PMMBegemot
09/30/2021, 3:32 PMkpgalligan
09/30/2021, 3:53 PMmaven-publish
and/or com.vanniktech.maven.publish
to simply replace the regular jar with the '-all' one and publish that. So far, publishing still seems to consider the main jar the primary artifact. The docs don't really get at what I'm trying to go (https://imperceptiblethoughts.com/shadow/publishing/#publishing-with-maven-publish-plugin). So far at best I'm able to get both jars published with the shadow jar mentioned in the module (not the pom), but using it as a dependency pulls in the regular jar and fails because of ClassNotFound type exceptions (for obvious reasons). I'm hoping somebody has a simple answer or example. Seems like it should be easy, but I still haven't found an example that works (with gradle 7+, anyway). Switching focus till late tomorrow but will try to extract a simple example and post. Thanks in advance!Tomas Kormanak
10/01/2021, 9:45 AMkotlin {
sourceSets {
val commonMain by getting { /* ... */ }
}
}
and
kotlin {
sourceSets {
commonMain { /* ... */ }
}
}
Gabriel Duncan
10/01/2021, 7:14 PMBen Madore
10/04/2021, 3:27 PMkotlin("jvm") version "1.5.31"
id("org.jetbrains.kotlin.plugin.spring") version "1.5.31"
id("org.jetbrains.kotlin.plugin.noarg") version "1.5.31"
id("org.jetbrains.kotlin.plugin.lombok") version "1.5.31"
id("io.freefair.lombok") version "5.3.0"
id("org.jetbrains.dokka") version "1.5.30"
but for some reason it looks like gradle is selecting 1.5.10
for the kotlin-stdlib-*
dependencies:
❯ gr dependencyInsight --dependency "org.jetbrains.kotlin:kotlin-stdlib-jdk8" --configuration kotlinCompilerPluginClasspathMain
executing gradlew instead of gradle
Type-safe dependency accessors is an incubating feature.
Type-safe project accessors is an incubating feature.
> Task :dependencyInsight
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10 (selected by rule)
variant "runtime" [
org.gradle.status = release (not requested)
org.gradle.usage = java-runtime (not requested)
org.gradle.libraryelements = jar (not requested)
org.gradle.category = library (not requested)
]
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20 -> 1.5.10
\--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
\--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
+--- org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31 (requested org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0)
| \--- org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31
| \--- kotlinCompilerPluginClasspathMain
\--- org.jetbrains.kotlin:kotlin-scripting-common:1.5.10 (requested org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8)
+--- org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31 (requested org.jetbrains.kotlin:kotlin-scripting-common:1.5.31) (*)
\--- org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.10
\--- org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31 (requested org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31) (*)
(*) - dependencies omitted (listed previously)
perhaps i just don’t understand how to read the dependencyInsights, but it’s unclear to me why it would choose that versionmcpiroman
10/04/2021, 4:56 PMplugins { kotlin("jvm") }
does not apply configurations like api
in subproject?Endre Deak
10/06/2021, 8:57 PM// custom task type to be able to create custom environment variables here
abstract class IntegrationTest : Test()
val integrationTest: SourceSet by sourceSets.creating {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.runtimeOnly.get())
val integrationTestTask = tasks.register<IntegrationTest>("integrationTest") {
description = "Runs integration tests."
group = "verification"
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath
}
tasks.withType<IntegrationTest> {
val envName = "local"
environment(
mapOf(
"KEY" to "myTestValue"
)
)
}
Alexander Suraphel
10/07/2021, 3:04 PMplugins {
id 'org.jetbrains.kotlin:android' version "$kotlin_version"
}
alternative syntax for:
apply plugin: 'kotlin-android'
? Apologies for the noob question.Alexander Suraphel
10/07/2021, 3:32 PMA problem occurred configuring root project ''.
> 'kotlin-android' plugin requires one of the Android Gradle plugins.
Please apply one of the following plugins to ':' project:
- com.android.application
- com.android.library
- com.android.dynamic-feature
- com.android.asset-pack
- com.android.asset-pack-bundle
- com.android.lint
- com.android.test
- com.android.instantapp
- com.android.feature
What am I missing?Endre Deak
10/08/2021, 10:22 PMcmd+option+L
(I’m using a mac) to reformat kotlin code, I want this to match with the format kotlinter uses
• when I run a gradle build, kotlinter should format not only the changed code, but everything
• I want kotlinter result to be applied before detekt is executed (so for example if I have a long line, kotlinter fixes it, so detekt doesn’t fail on that)
From all things (idea, detekt, kotlinter) I’m using the latest versions:
• IDEA 2021.2.2 Ultimate (212.5284.40)
• detekt: 1.18.1
• kotlinter: 3.6.0
I always run into some problems:
• idea autoformat doesn’t match kotlinter format
• kotlinter only formats changed lines not the entire file
Relevant gradle parts:
plugins {
base
kotlin("jvm")
id("java")
id("idea")
id("com.google.cloud.tools.jib")
id("org.jmailen.kotlinter")
id("org.jetbrains.dokka")
id("io.gitlab.arturbosch.detekt")
`version-catalog`
application
}
detekt {
toolVersion = findProperty("detektVersion") as String
config = files("config/detekt/detekt.yml")
buildUponDefaultConfig = true
autoCorrect = true
debug = true
}
tasks.detekt {
dependsOn("formatKotlinMain")
}
// right now it's a single project, but might be a multiproject later
allprojects {
apply(plugin = "idea")
apply(plugin = "org.jmailen.kotlinter")
apply(plugin = "io.gitlab.arturbosch.detekt")
}
kotlinter {
ignoreFailures = false
indentSize = 4
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
}
Anthony Nixon
10/13/2021, 2:03 PMSimon Meskens
10/13/2021, 5:15 PMTomasz Krakowiak
10/15/2021, 10:07 AMCaused by: org.gradle.api.UnknownDomainObjectException: Included build 'my-library' not found in build 'my-project'.
Justin Yue
10/16/2021, 3:42 AMimplementation "com.google.android.libraries.maps:maps:3.1.0-beta"
implementation "com.google.maps.android:maps-v3-ktx:3.0.1"
But I'm receiving the following error:
2 files found with path 'build-data.properties'.
Adding a packagingOptions block may help, please refer to
<https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html>
for more information
The link provided sends me to a website that doesn't exist, so how should I go about modifying packagingOptions?Emil Kantis
10/16/2021, 5:46 PM./gradlew :my-app:test --info
twice in a row, the compileKotlin task shows as up-to-date
but still takes around 1 second to execute, is this to be expected? Once you have a few projects it adds a few seconds here and there to test startup time which feels incredibly unnecessary
> Task :my-app:compileKotlin UP-TO-DATE
Excluding []
Excluding []
Build cache key for task ':my-app:compileKotlin' is 17a575849d631a792fda5556b1b04bd2
Skipping task ':my-app:compileKotlin' as it is up-to-date.
:my-app:compileKotlin (Thread[Daemon worker Thread 3,5,main]) completed. Took 1.179 secs.