https://kotlinlang.org logo
Title
g

gsala

02/14/2023, 10:16 AM
I tried bumping Gradle to 8.0 but I’m running into this error:
> ‘compileDebugJavaWithJavac’ task (current target is 11) and ‘kaptGenerateStubsDebugKotlin’ task (current target is 17) jvm target compatibility should be set to the same Java version.
I’m running Gradle on JVM version 17, and I have set the `sourceCompatibility`/`targetCompatibility`/`jvmTarget` options in the my
build.gradle
files to
JavaVersion.VERSION_11
. The error disappears if I align the Gradle JVM and target versions to be either 11 or 17, but I didn’t think these versions needed to be aligned. Does anyone have any input on what versions we should be using?
c

Charlie Tapping

02/14/2023, 11:46 AM
Its a bug
you can fix with
tasks.withType<KaptGenerateStubsTask>().configureEach { kotlinOptions.jvmTarget = libs.versions.java.bytecode.version.get() }
g

gsala

02/14/2023, 12:48 PM
Do you have a link to an issue tracking this?
c

Charlie Tapping

02/14/2023, 1:37 PM
You can read Robs post on SO here for more info
c

Chrimaeon

02/14/2023, 4:13 PM
Setting the source/targetCompatibility is not enough any more. you need to configure the
toolchain
correctly. I.e. read over here https://blog.jetbrains.com/kotlin/2021/11/gradle-jvm-toolchain-support-in-the-kotlin-plugin/
i

itnoles

02/17/2023, 1:58 PM
kotlin { toolchain(11) } inside android { }?
b

Billy Newman

05/05/2023, 2:43 PM
I am running into that same issue, using the following with gradle 8:
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlin {
    jvmToolchain(17)
}
kotlinOptions {
    jvmTarget = "17"
}
Still no luck, any ideas?
g

gsala

05/05/2023, 3:31 PM
Check out this PR in Now In Android. They have a workaround
Part of it got corrected here though https://github.com/android/nowinandroid/pull/689
i

itnoles

05/05/2023, 3:35 PM
Intellij IDEA keep bumping Java Runtime up to 17 (now?), it forcing AGP to increase it
b

Billy Newman

05/05/2023, 4:07 PM
Ideas? This is in my android block in build.gradle file
i

itnoles

05/05/2023, 4:09 PM
kotlinOptions {} not work inside of android {}?
b

Billy Newman

05/05/2023, 4:10 PM
More so its having an issue finding tasks.withType I think
Syntax issue as I am using groovy , not kotlin
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        jvmTarget = "11"
    }
}
This is maddening:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: <https://kotl.in/gradle/jvm/toolchain>
i

itnoles

05/06/2023, 7:19 PM
tasks.withType<KaptGenerateStubsTask>().configureEach {
    kotlinOptions.jvmTarget = "11"
}