Skip to content
Latchkey

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.

gradle output
* 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.

build.gradle.kts
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.

build.gradle.kts
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 Java release and Kotlin jvmTarget set to the same version.

Frequently asked questions

What causes ""Inconsistent JVM-target compatibility""?
The Kotlin jvmTarget (or its toolchain) is set to a different version than the Java release/targetCompatibility, so the two tasks emit incompatible bytecode.
How do I fix "Inconsistent JVM-target compatibility"?
A single Java toolchain drives both Java and Kotlin compilation to the same target.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card