So I interpreted the line "Kotlin 2.2.0 brings man...
# getting-started
s
So I interpreted the line "Kotlin 2.2.0 brings many updates to the JVM. The compiler now supports Java 24 bytecode and ..." in What's new in Kotlin 2.2 to mean that I can compile my Kotlin project to Java 24 bytecode, but when I try to do just that (via
jvmToolchain(24)
and using Kotlin 2.2.0, Gradle 8.14.1, and Amazon's 24.0.1 Corretto JDK a
./gradlew clean build
gives me:
Copy code
Kotlin does not yet support 24 JDK target, falling back to Kotlin JVM_22 JVM target
Did I understand something wrong, or is this a bug?
h
Maybe it's only about using Java classes built with target 24 and not about outputting target 24. I haven't tried 2.2.0 myself yet.
s
it certainly looks that way. I already switched over to Kotlin 2.2 for two microservices that have to deal with urls which contain '$', so multidollar string interpolation makes the code cleaner 🙂
s
I've just tried assembling some minimal Gradle project using Gradle 8.14.1, Kotlin 2.2.0 and Corretto 24.0.1 with
Copy code
kotlin {
    jvmToolchain(24)
}
and it compiled just fine with compiled classes properly indicating JVM 24 target. Maybe double check your setup to ensure nothing is overwriting Kotlin version used for compilation
thank you color 1
s
so strange, for me it looks like I use basically the same. here's my config.
Copy code
kotlin {
    // uses org.gradle.java.installations.auto-download=false in gradle.properties to disable auto provisioning of JDK
    jvmToolchain(JDK.version)
    compilerOptions {
        extraWarnings = true
        //kotlinlang.org/docs/whatsnew22.html#changes-to-default-method-generation-for-interface-functions
        jvmDefault = JvmDefaultMode.NO_COMPATIBILITY
    }
}
with JDK.version being defined in buildSrc:
Copy code
object JDK {
    const val version = 24
}
I have a multimodule setup, but each uses
Copy code
kotlin {
    // uses org.gradle.java.installations.auto-download=false in gradle.properties to disable auto provisioning of JDK
    jvmToolchain(JDK.version)
}
just to reenforce the jdk (and if I remember correctly I do have to reenforce the jvmToolchain.
e
there's no reason for Kotlin to target Java 24 bytecode. the compiler does need to be able to understand it so that you can build with Java 24 in the compile classpath
s
I want to try out Compact Object Header optimization. I'm not sure if the bytecode has to be JDK24 bytecode, or if it's enough if the jar is executed by a Java 24 JDK. Does somebody know?
e
it is not related to the bytecode, it's a part of how the JVM represents any object
👍 1