Is ```java { toolchain { .. } }``` a replacemen...
# gradle
u
Is
Copy code
java {
   toolchain { .. }
}
a replacement for this
Copy code
tasks.withType(JavaCompile).configureEach { task ->
        task.sourceCompatibility = JavaVersion.VERSION_17
        task.targetCompatibility = JavaVersion.VERSION_17
    }
and this
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { task ->
        task.kotlinOptions {
            jvmTarget = "17"
?
You can replace
Copy code
tasks.withType(JavaCompile).configureEach { task ->
        task.sourceCompatibility = JavaVersion.VERSION_17
        task.targetCompatibility = JavaVersion.VERSION_17
    }
with
Copy code
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}
u
how about kotlin?
m
just change
java
to
kotlin
if you are using Gradle Kotlin DSL
u
unfortunately not .. just wondering, is that single declaration then supposed to work for all modules & both java and kotlin?
c
It's intended to work only for the current module, for both Java and Kotlin
u
just to be sure -- kotlin bytecode target will be set with the
java { .. }
syntax, correct? will it work for android module as well? the sample I posted works only for pure java modules