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

wakingrufus

12/14/2023, 9:19 PM
in gradle 7 with KGP 1.8.22, has anyone gotten
Copy code
'compileTestJava' task (current target is 11) and 'compileTestKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
By default will become an error since Gradle 8.0+! Read more: <https://kotl.in/gradle/jvm/target-validation>
Consider using JVM toolchain: <https://kotl.in/gradle/jvm/toolchain>
but they have
Copy code
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}
c

Chris Lee

12/14/2023, 9:21 PM
what isn’t set is the Kotlin java version to use, they must match.
w

wakingrufus

12/14/2023, 9:23 PM
yeah... I just read in the docs that setting that is optional and that if you set the java toolchain, kotlin will use that
but maybe that is not the case?
c

Chris Lee

12/14/2023, 9:23 PM
That’s the case for newer Gradle versions, not older ones.
hence the warning.
w

wakingrufus

12/14/2023, 9:23 PM
ahh
v

Vampire

12/14/2023, 9:56 PM
Nah, that has nothing to do with the Gradle version, but with the KGP version.
The warning says that such inconsistent configuration will be an error then, doesn't it?
I would suspect that even though the toolchain is used, the JVM target additionally is overwritten to 8
Or the KGP version is that old that it does but consider the toolchain
w

wakingrufus

12/14/2023, 9:58 PM
yeah, but I am not doing that in my script, so it should be set automatically to match the toolchain
KGP is 1.8.22 so not super old
but maybe old enough
v

Vampire

12/14/2023, 9:58 PM
No
Should work with that
Maybe your have some plugin that sets it or similar
1
w

wakingrufus

12/14/2023, 9:59 PM
im pretty sure not, but i can dig into that
t

tapchicoma

12/15/2023, 12:00 PM
Do you explicitly specify somewhere
jvmTarget
? It will override the value from toolchain.
w

wakingrufus

12/15/2023, 4:02 PM
i used to have
Copy code
subprojects {
    plugins.withId("org.jetbrains.kotlin.jvm"){
        tasks.withType<KotlinCompile> {
            kotlinOptions {
                languageVersion = "1.6"
                apiVersion = "1.6"
                jvmTarget = "11"
            }
        }
    }
}
on my root build, but i changed that to
Copy code
subprojects {
    plugins.withId("org.jetbrains.kotlin.jvm"){
        tasks.withType<KotlinCompile> {
            kotlinOptions {
                languageVersion = "1.6"
                apiVersion = "1.6"
            }
        }
    }
}
now and that is when the warning showed up
t

tapchicoma

12/15/2023, 9:35 PM
then it is strange, please try to update Kotlin version in the repo