Skip to content
Latchkey

Kotlin "Inconsistent JVM-target compatibility" between compileJava and compileKotlin in CI

Gradle checks that the Java and Kotlin compile tasks in a module target the same bytecode. When compileJava and compileKotlin disagree (for example 1.8 vs 17), Gradle fails with "Inconsistent JVM-target compatibility". The fix is to set one target for both, ideally via a JDK toolchain.

What this error means

The build fails with "Inconsistent JVM-target compatibility detected for tasks 'compileJava' (1.8) and 'compileKotlin' (17)".

Gradle
> Task :app:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 17)
jvm target compatibility should be set to the same Java version.

Common causes

Java and Kotlin targets set independently

Java sourceCompatibility is 1.8 while kotlinOptions.jvmTarget/compilerOptions.jvmTarget is 17 (or vice versa), so the two tasks disagree.

The runner JDK differs from the configured target

A different JDK provided by setup-java changes one task target while the other stays at a hardcoded value.

How to fix it

Use one JDK toolchain for both

Set a Kotlin/Java toolchain so both compile tasks target the same bytecode version.

build.gradle.kts
kotlin {
    jvmToolchain(17)
}
java {
    toolchain { languageVersion.set(JavaLanguageVersion.of(17)) }
}

Provision the matching JDK in CI

Give the runner the JDK the toolchain expects with setup-java so provisioning is deterministic.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: 'temurin'
    java-version: '17'

How to prevent it

  • Set a single jvmToolchain(...) instead of separate Java and Kotlin targets.
  • Pin the CI JDK with setup-java to match the toolchain.
  • Keep the same JDK version across all modules of the build.

Frequently asked questions

What causes ""Inconsistent JVM-target compatibility""?
Java sourceCompatibility is 1.8 while kotlinOptions.jvmTarget/compilerOptions.jvmTarget is 17 (or vice versa), so the two tasks disagree.
How do I fix "Inconsistent JVM-target compatibility"?
Set a Kotlin/Java toolchain so both compile tasks target the same bytecode version.

Related guides

References

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