I've started seeing the following get printed when...
# gradle
e
I've started seeing the following get printed when running gradle tasks from the command line:
Copy code
> Task :buildSrc:compileKotlin
'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
My buildSrc
build.gradle.kts
is in 🧵 and I believe I'm setting all of the Java and Kotlin targets correctly.
Copy code
@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
  `kotlin-dsl`
}

repositories {
  mavenCentral()
  google()
}

tasks.withType<JavaCompile> {
  sourceCompatibility = libs.versions.jdk.get()
  targetCompatibility = libs.versions.jdk.get()
}

kotlin {
  jvmToolchain {
    (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(libs.versions.jdk.get()))
  }
}

tasks.withType<KotlinCompile>().configureEach {
  kotlinOptions {
    jvmTarget = libs.versions.jdk.get()

    allWarningsAsErrors = true
  }
}

dependencies {
  implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
  implementation(libs.buildscript.android)
  implementation(libs.buildscript.kotlin)
  implementation(libs.buildscript.detekt)
  implementation(libs.kotlinx.serialization)
  implementation(libs.ejson)
}
t
kotlin-dsl forces jvm target to 1.8, so you have to set toolchain in
buildSrc
to 8
e
Interesting. Is the kotlin-dsl jvm target exposed anywhere so that I can set the toolchain based on that?
p
e
Oh excellent. Now I just need 1.6.0 🕕
t
1.8 is set by Gradle as Gradle itself supports running on JDK 1.8+. Kotlin-DSL sets jvm target here, where current target itself is here.
e
I'm fine with it being 1.8 I was just trying to make the warning go away (which it seems like Kotlin 1.6.0 will do)
t
'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
- this warning was introduced in the Kotlin 1.5.30 and does not relate to the linked issue above. Generally best solution would be to set toolchain to 8 java version. Also you could disable this warning at all: https://kotlinlang.org/docs/gradle.html#check-for-jvm-target-compatibility
e
Wouldn't the linked issue apply since I don't have any Java sources? If not, would the solution be to set the toolchain to
kotlinDslPluginOptions.jvmTarget.get()
? If so, is that something the plugin should do?
t
You may still have Groovy compiled classes 🙂 But there was also a bug in 1.5.30 which produce this warning on empty java sources. Should be fixed in 1.6.0
p
This made the warning go away for me (in
buildSrc/build.gradle.kts
):
Copy code
java {
  sourceCompatibility = JavaVersion.VERSION_1_8
  targetCompatibility = JavaVersion.VERSION_1_8
}
I expect to be able to delete the above code after updating to Kotlin 1.6 (I don’t have any Java code in
buildSrc
).