https://kotlinlang.org logo
#gradle
Title
# gradle
m

mbonnin

10/04/2023, 5:12 PM
Why is the host java version an input to
compileKotlin
? As long as I set Kotlin
jvmTarget
(and Java
options.release
?), is there any reason 2 different JDKs would produce different class files?
Bumped into this: https://youtrack.jetbrains.com/issue/KT-45611 which states that non-JVM doesn't depend on the host java version but JVM might? But not sure why...
v

Vampire

10/05/2023, 9:40 AM
Probably same as with Java? If you compile against different versions, different methods can be selected and written to the class file. For example if you use
ByteBuffer#flip
which used to return
Buffer
and now returns
ByteBuffer
.
m

mbonnin

10/05/2023, 9:41 AM
Isn't that the whole point of
--release
?
I'd expect the Kotlin compiler to either set
--release
according to
jvmTarget
or allow me to configure it
v

Vampire

10/05/2023, 10:12 AM
Isn't that the whole point of --release ?
Yes
I'd expect the Kotlin compiler to either set --release according to jvmTarget or allow me to configure it
If I look at issues like https://github.com/Kotlin/kotlinx.serialization/pull/2350, I'd say it does not.
👀 1
a

Alexander.Likhachev

10/05/2023, 11:34 AM
Currently the recommended way to deal with different versions is JVM toolchains. https://kotl.in/gradle/jvm/toolchain The toolchains feature will properly configure Kotlin’s
jvmTarget
, Java’s
targetCompatibility
, choose the right Java stdlib, configure publishing attributes, etc. It doesn’t cause the Kotlin compiler to be executed on the old JDK, but configures the compilation to run against that JDK. Manual configuration of
jvmTarget
is kinda a low-level configuration key, similar to Java’s
--target
, not
--release
. The Kotlin compiler has the argument
-Xjdk-release
that serves the same needs as
--release
of the Java compiler, however it’s not yet stabilized
m

mbonnin

10/05/2023, 11:38 AM
@Alexander.Likhachev my goal is to avoid toolchains. I'd like to avoid downloading a jdk11 if I have a jdk21 on my machine (or in CI)
Just use jdk21 everywhere, also makes sure I get the nice performance improvements in latest jdks
3 Views