Gradle "Inconsistent JVM-target compatibility detected" in CI
When a project compiles both Java and Kotlin, Gradle checks that compileJava and compileKotlin target the same JVM bytecode version. A mismatch (for example Java targeting 17 while Kotlin targets 1.8) fails the build because the outputs would be inconsistent.
What this error means
The build fails with "‘compileJava’ task (current target is 17) and ‘compileKotlin’ task (current target is 1.8) jvm target compatibility should be set to the same Java version."
> Inconsistent JVM-target compatibility detected for tasks 'compileJava'
(17) and 'compileKotlin' (1.8).
This will become an error in future versions of the Kotlin Gradle plugin.Common causes
Java and Kotlin target different versions
The Java toolchain or sourceCompatibility targets one version while kotlinOptions.jvmTarget (or the Kotlin compiler options) targets another.
A toolchain set for one language but not the other
Applying a Java toolchain without aligning the Kotlin JVM target leaves the two compile tasks disagreeing.
How to fix it
Set one toolchain for both
Configure a single Java toolchain so both compile tasks derive the same target.
kotlin {
jvmToolchain(17)
}Pin Java and Kotlin targets explicitly to match
If you set targets directly, make the Kotlin JVM target equal the Java target.
java { sourceCompatibility = JavaVersion.VERSION_17 }
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}How to prevent it
- Prefer
jvmToolchainso both compilers share one version. - Keep Java and Kotlin JVM targets in sync when set manually.
- Review target settings when upgrading the Kotlin plugin.