Gradle "Inconsistent JVM-target" Kotlin/Java - Fix in CI
Gradle detected that the Java and Kotlin compile tasks target different JVM bytecode versions. A mixed Java/Kotlin module must compile both to the same target, and they diverged.
What this error means
The build fails with Inconsistent JVM-target compatibility detected for tasks 'compileJava' (N) and 'compileKotlin' (M), naming the two mismatched targets.
* What went wrong:
Execution failed for task ':app:compileKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileJava' (17)
and 'compileKotlin' (21).Common causes
Kotlin jvmTarget differs from Java release
The Kotlin jvmTarget (or its toolchain) is set to a different version than the Java release/targetCompatibility, so the two tasks emit incompatible bytecode.
Only one of the two configured
Setting the Java release but leaving Kotlin on its default (or vice versa) lets them drift apart.
How to fix it
Use one toolchain for both
A single Java toolchain drives both Java and Kotlin compilation to the same target.
kotlin {
jvmToolchain(17) // applies to Java and Kotlin compile tasks
}Set matching targets explicitly
If not using a shared toolchain, set both to the same version.
tasks.withType<JavaCompile> { options.release.set(17) }
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}How to prevent it
- Drive both Java and Kotlin from a single
jvmToolchain, or keep Javareleaseand KotlinjvmTargetset to the same version.