We are currently working on a project that uses Kotlin and Gradle, and we are interested in testing the Leyden project included in the Java 24 Early Access (EA) version. However, we have encountered an issue where our build system shows a message indicating that there is no compatible version of Kotlin with Java 24. We are aware that the latest stable version of Kotlin is 2.0.20, which supports up to Gradle 8.8, but it seems there might be compatibility issues with Java 24 EA.
Could anyone provide insights or updates on whether there is a Kotlin version that is compatible with Java 24 EA? Additionally, if there are any workarounds or upcoming releases that might address this compatibility issue, we would greatly appreciate the information.
Thank you!
1 Like
We are aware that the latest stable version of Kotlin is 2.0.20, which supports up to Gradle 8.8, but it seems there might be compatibility issues with Java 24 EA.
In practice for JVM projects, Kotlin 2 works fine on Gradle 8.10.
So I doubt that there are any issues if Gradle itself works on JDK 24.
In my experience, older Kotlin version works well with new JDKs, so I don’t see a reason why you shouldn’t go and use Kotlin with JDK 24
If you are not specifying an explicit Java target version on the Kotlin compiler tasks then it will default to the executing JDK. This will attempt to target Java 24 bytecode which is not yet supported by the compiler.
You can fix this by setting the Java target and source versions to something lower. Currently 22 is the highest target that’s supported in Kotlin 2.0 or newer (https://youtrack.jetbrains.com/issue/KT-66703). Generally people have this set low to 8 or 11 or such as there’s very little which changes today in the compiler’s output when targeting new versions.
Another option is to specify a JVM toolchain, but I would not recommend that as there’s no reason to force the use of old JDKs simply to cross-compile to target an older Java bytecode version since every JDK supports that natively.
Kotlin does not yet support 24 JDK target, falling back to Kotlin JVM_21 JVM target
I am getting above warning during build, I don’t think that I would be able to test the java 24 feature(specially layden project) if Kotlin falling back to JVM_21 target.
please correct me if I am wrong.
And here is the logs if I am using java 24 while setting jvmTarget=21 for kotlin
* What went wrong:
Execution failed for task ':commons-context:kaptGenerateStubsKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileJava' (24) and 'kaptGenerateStubsKotlin' (21).
Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation
Thanks
Right. This message is about the Java bytecode target version which should not require being set to 24. You can set it to 21, 17, or even 8. The only reason you would need it set to 24 is if there were actual bytecode capabilities introduced by Leyden. As I understand it, the Leyden changes are entirely in the VM and around expansion of AppCDS which should work for classfiles with any bytecode target.
To resolve that warning, you need to change your Java code to also target 21. This should not prevent you from using JDK 24 or the warmup/training run/AppCDS stufff that Leyden provides.
1 Like