How to know which `kotlinOptions.jvmTarget` versio...
# multiplatform
a
How to know which
kotlinOptions.jvmTarget
version is the latest? 11, 17, 1.8..etc. ?
a
finding out the max JVM target seems unusual, why do you want to find out? Newer versions of Kotlin have a type for most compiler variables, so you could use the following in a Gradle script:
Copy code
org.jetbrains.kotlin.gradle.dsl.JvmTarget.values().max().target
👍🏻 1
b
Use compilerOptions.jvmTarget for the above
plus1 1
a
We're working on a new KMM app and we want to target the latest JVM bytecode generation (if my understanding is correct)
b
Why would you need that? Usually folks target either java 8 or latest lts which as of now is jdk 17
a
Also because on the build machine we're getting
No matching toolchains found for requested specification: {languageVersion=17, vendor=any, implementation=vendor-specific} for MAC_OS on x86_64.
so it came to our attention the versioning part.
b
Also for kmm I think jdk 11 is the latest supported for android
a
I'd rather target the latest LTS if that's possible
b
Ah, that's because gradle does not download toolchains out of the box and expects them to be present in device instead
There's a plugin if you're looking for toolchain download too
a
I can see the value in targeting the latest LTS release, but I think it’s tough to do it automatically in a way that would save time :) https://xkcd.com/1205/ https://endoflife.date/java has an API for fetching the latest LTS release - I know it’s possible to get that data into a GitHub Action (for example), though I’ve never done it
a
Okay, the most recommended would suffice in this case
Which honestly dunno the source-of-truth to follow/find
a
when it comes to Java I think LTS is a very loose standard anyway. IIRC there’s no binding agreement that vendors have to provide LTS just because it’s Java 17, even though they implement spec.
a
Here I see its setting to
17
for example
<https://kotlinlang.org/docs/get-started-with-jvm-gradle-project.html#explore-the-build-script>
And
<https://kotlinlang.org/docs/gradle-compiler-options.html#attributes-specific-to-jvm>
mentions possible options and that default is
1.8
without justification on when to choose which.
and that's the root of my confusion tbh
a
If you’re writing an app in Kotlin, then it usually doesn’t really matter which Java version you compile to. If you’re writing a library, then it matters more.
a
Working on both. An Android/iOS app using KMM/ComposeUI, and a number of libraries to be included in such app/project.
a
are the libraries you’re working on to be used publicly, or are they just for your app?
a
just by our app
does it make a difference when making the decision @Adam S
a
when writing a library that will be used publicly, it’s usually best to try and use the lowest LTS version of Java, so that the library can be used by more projects. But when writing apps, or libraries that will only be used in your app, then it’s usually best to try and use the highest LTS version of Java (so you have the latest features, fixes, improvements). Of course there might be some constraints, like you need to use the latest version of Java for some Java feature, or if Android prevents you from using some Java versions
a
That's exactly why I was looking for the latest LTS (which I cannot spot)
a
gotcha
it’s not going to be in the KGP, but you can look it up. I already mentioned https://endoflife.date/java, but there’s also https://en.wikipedia.org/wiki/Java_version_history
a
Yeah I got that latest so far is 20, however not sure how to target that in kotlinOptions.jvmTarget
b
Simply kotlinOptions.jvmTarget = "20"
Note that 20 is non-LTS
a
Okay will try that
Thanks 🙏
j
There is nothing about 20 that makes it non-LTS
LTS is a property of vendor distributions, not of the OpenJDK version intrinsically
Any vendor can make any version LTS
Besides, the best LTS is actually staying on the latest version which is currently 20 and then switching to 21 when it's out, and then 22 and so on
a
@jw Thanks for your input. I wanted to target 20 initially.
Tho... apparently using
JavaVersion._VERSION_20
for_
sourceCompatibility
and
targetCompatibility
throws
'VERSION_20' is marked unstable with @Incubating
and
Java 20 major version. Not officially supported by Gradle. Use at your own risk.
j
I believe Gradle 8.3 has official support for 20
a
Trying that out now.
Got
gradle-8.3-rc-1
working with
8.2.0-alpha13
and there's absolutely no way to make sure if the Android Gradle Plugin is the latest.
142 Views