https://kotlinlang.org logo
#gradle
Title
# gradle
t

thanksforallthefish

01/18/2023, 7:34 AM
Hello, I am a bit confused by intellij warnings in gradle file. in particular, we have
Copy code
kotlin {
  jvmToolchain {
    languageVersion.set(JavaLanguageVersion.of(17))
  }
  sourceSets.all {
    languageSettings {
      progressiveMode = true
    }
  }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17 //see: <https://youtrack.jetbrains.com/issue/IDEA-252328>
    freeCompilerArgs = ["-Xjsr305=strict", "-Xemit-jvm-type-annotations", "-opt-in=kotlin.RequiresOptIn"]
  }
}
with kotlin 1.8 and groovy build file.
sourceSets.all
is suggested to be replaced with
source.configureEach
, which seems to work but it deviates from kotlin docs: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#language-settings. moreover, using
configureEach
leads to
languageSettings
generating a warning as
method call is ambiguous
. what is the best approach here? second confusing (or better, I am not sure what to do) warning is the deprecation of `kotlinOptions`: idea still does not fully support language version, as per https://youtrack.jetbrains.com/issue/IDEA-252328, but the suggested solution requires replacing toolchain with
unfortunately no improvements were made yet. The sourceCompatibility and targetCompatibility are safe options for now.
source and target compatibility, and toolchain are mutually exclusive, hence the use of
kotlinOptions
. I am mostly concern about upgrading to gradle 8, probably kotlin options will go then, is there another option?
g

gildor

01/18/2023, 7:38 AM
General rule that you should always prefer lazy configuration
configureEach
instead of
all
(but not sure about what is the issue with languageSettings, in general all/configureEach should be the same
t

thanksforallthefish

01/18/2023, 7:41 AM
with
all
intellij warns of
No candidates found for method call languageSettings.
, in the end it’s just intellij but was looking for an option that would make ide happy too
I should probably migrate to kotlin gradle file, I think ide support is a bit better there
g

gildor

01/18/2023, 7:42 AM
Honestly with Groovy it never works for me in IDE, it’s essentially useless, works as text editor
v

Vampire

01/18/2023, 7:47 AM
While editing a Groovy DSL build script in the IDE, that's exactly the one case where the
-all
distribution is helpful to improve developer life, but really only while editing the file. But yeah, Kotlin DSL does not only have "a bit" better IDE support, but amazingly better IDE support. :-)
Also upgrading Gradle has nothing to do with your problem, Kotlin Options are from the Kotlin Gradle plugin so independent from Gradle version.
And regarding the
kotlinOptions
, as far as I remember you should use something like
Copy code
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
instead
t

thanksforallthefish

01/18/2023, 8:07 AM
Also upgrading Gradle has nothing to do with your problem, Kotlin Options are from the Kotlin Gradle plugin so independent from Gradle version.
ah, fair point, thanks for the explanation
427 Views