Hello, not sure if this is the right channel or no...
# general-advice
j
Hello, not sure if this is the right channel or not, please let me know if there is another. If we use a newer Kotlin Compiler (say 2.2+) / Gradle Plugin in a project that produces a library (klib or jar, doesn’t matter) if we want it to be compatible with Kotlin 2.1 (a previous version) if we set the languageVersion and apiVersion to 2.1 will a consuming project using an older compiler (2.1) be able to use it without throwing an error saying the library was built with a newer version?
m
Yes, this is the whole point of
languageVersion
❤️ 1
🎢 1
You can even set
languageVersion = 2.2
and
kotlinc:2.1
will be able to process it (as long as you're not using
2.2
features)
(that last point is thanks to the best effort n+1 forward compatibility guarantee)
j
okay great. we just integrated kotest and it was built with 2.2 and we are using 2.1 and the compiler is saying it can’t read the the newer version. just making sure if we use a newer compiler and we use the languageVersion we don’t force our customers to do the same (upgrade their compiler).
m
So the other fine print of this is that
languageVersion
is only for JVM. Other targets have no support for `languageVersion`
If you're doing KMP you're forced to use a greater kotlinc for consuming as the one you used for building
j
oh thats our use case
bummer
glad i asked here!
m
The somewhat good news is that the KMP ecosystem moves usually faster so your consumers will hopefully be able to upgrade faster
Most of the ecosystem out there is moving on the latest KGP relatively fast (~couple of months or so)
Also keep in mind that if a transitive dependency (like Kotlin-stdlib) exposes 2.2 metadata, you can set
languageVersion
all you want but your consuomers might still choke on the dependencies
So tldr; it's complicated. Sorry I sounded a bit enthusiastic in the beginning at this thread
j
lol ngl you had me in the first half 😉 but ya thats what i was essentially concerned about
😄 1
thanks for confirming
we can work around it. as long as i understand
m
sorry fo rr the false hopes 😅
What we do is set
languageVersion
for JVM consumers and wait a couple of months before we upgrade KGP for the non-JVM consumers
j
ya its hard in this case cause our test framework is forcing this so we’ll figure it out
but thank you very much for informing me
kodee loving 1
m
Sure thing! Best of luck in your compatibilty journey!
❤️ 1
e
in the future this may get easier with BTA - you can use a newer version of KGP throughout your project, but older versions of the Kotlin compiler in specific modules https://kotlinlang.org/docs/build-tools-api.html
👍 1
m
Yesss, that's only JVM for now though
🫠 1