I tried bumping Gradle to 8.0 but I’m running into...
# android
g
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?
😶 2
c
Its a bug
you can fix with
tasks.withType<KaptGenerateStubsTask>().configureEach { kotlinOptions.jvmTarget = libs.versions.java.bytecode.version.get() }
g
Do you have a link to an issue tracking this?
c
You can read Robs post on SO here for more info
c
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
kotlin { toolchain(11) } inside android { }?
b
I am running into that same issue, using the following with gradle 8:
Copy code
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlin {
    jvmToolchain(17)
}
kotlinOptions {
    jvmTarget = "17"
}
Still no luck, any ideas?
g
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
Intellij IDEA keep bumping Java Runtime up to 17 (now?), it forcing AGP to increase it
b
Ideas? This is in my android block in build.gradle file
i
kotlinOptions {} not work inside of android {}?
b
More so its having an issue finding tasks.withType I think
Syntax issue as I am using groovy , not kotlin
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        jvmTarget = "11"
    }
}
This is maddening:
Copy code
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
Copy code
tasks.withType<KaptGenerateStubsTask>().configureEach {
    kotlinOptions.jvmTarget = "11"
}
535 Views