Law

Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac'

After upgrading Gradle to 8.13, I encountered this error after compiling.

Execution failed for task ':app:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (23) and 'compileDebugKotlin' (21).

It seems I need to specify the line below in build.gradle.kts

kotlin {
    jvmToolchain(23)
}

So, compileOptions and tool chain should match.

compileOptions {
  sourceCompatibility = JavaVersion.VERSION_23
  targetCompatibility = JavaVersion.VERSION_23
}
kotlin {
  jvmToolchain(23)
}