Hi! Whats the differences when setting these settings? ```java.sourceCompatibility = JavaVersion.VER...
m
Hi! Whats the differences when setting these settings?
Copy code
java.sourceCompatibility = JavaVersion.VERSION_17
or
Copy code
withType<JavaCompile>().configureEach {
        targetCompatibility = JvmTarget.JVM_17.target
    }
Which should I use and why? Want to understand the reason
Or should I use JVM toolchain?
Copy code
kotlin {
    jvmToolchain {
        (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(17))
    }
}
Then I dont need to specify sourceCompatibility and targetCompatibility. Am I right ?
v
I would go with the latter. Then Gradle can be run with any supported version like Java 8, but the Java 17 toolchain is used for compiling the code. The cast though looks suspicious. Besides that your last snipped does not look correct. If it is about a Kotlin project, see https://blog.jetbrains.com/kotlin/2021/11/gradle-jvm-toolchain-support-in-the-kotlin-plugin/ and generally https://docs.gradle.org/current/userguide/toolchains.html
m
I changed it to
Copy code
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}