QQ: If I am a library author, can I update the lib...
# announcements
p
QQ: If I am a library author, can I update the library's kotlin version without requiring its consumers to update as well? Specifically 1.3.72 -> 1.4.0
1
z
If you want to use 1.4.0 stdlib features, you can't - your consumers will need the new library or crash. If you want to just use 1.4 language features, I think you could stay on 1.3 and tell the compiler to use language level 1.4.
a
how do you tell the compiler to use language level 1.4?
p
How do I stay on 1.3 and ask compiler to use 1.4? I just want trailing commas tbh in my libraries. Nothing I need from 1.4 stdlib (for now)
😂 1
u
You can update the Kotlin compiler to 1.4, and pass
-api-version 1.3
. This will allow you to use new language features, but not the new API. It’s called
apiVersion
in Gradle, I think
👍 3
👏 1
p
Sweet. I'm on maven (for reasons), so I'll just add a prop. Found this: https://kotlinlang.org/docs/reference/using-maven.html Sidenote: This still lists 1.4 as experimental
language version would still be 1.4 (or unspecified, right?)
u
Yes, language version defaults to the compiler version, if not specified
z
Seems like
apiVersion
doesn’t actually change the version of the stdlib that is depended on. Should it? I think this is a requirement for libraries that want to use 1.4 but not automatically drag the 1.4 stdilb into their consumers’ transitive deps, otherwise they need to explicitly configure dependency resolution – right?
u
Oh, you’re right,
-api-version
is not enough, you also need to tell the build to avoid adding dependency on the default kotlin-stdlib, and depend manually on 1.3 instead. And in this case, I suppose
-api-version
is not even useful anymore. So instead of my initial advice, one should use Kotlin compiler 1.4, but with an explicit dependency on kotlin-stdlib 1.3. No need for
-api-version
. Then it will work as intended: 1.4 language features are enabled, 1.4 stdlib APIs are not. (Note that telling the Kotlin compiler 1.3 to use language 1.4 is generally not OK for libraries because it moves the compiler into the “pre-release” mode so that produced binaries will not be readable by the released 1.4+ compilers.)
😮 2
🙏 1
p
Is there a problem with depending on 1.4 stdlib if I don't use any 1.4 features?
z
I think I got this working, but you also need
apiVersion
to avoid warnings. It’s a lot more work than just not upgrading to 1.4 at all.