https://kotlinlang.org logo
#library-development
Title
# library-development
m

mbonnin

06/21/2021, 7:02 PM
I just got hit by
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16
and I'm wondering how safe it is to compile libs with Kotlin 1.5 if you expect consumers to use 1.3 or 1.4 for some reason. I was under the impression that it would work but this message seems to indicate otherwise. There are a few stack overflow github issue and everytime the solution seems to bump the Kotlin version in the consumer project, which might not always be possible easily. Has anyone more details about how safe it is?
e

ephemient

06/21/2021, 9:06 PM
if you expect Kotlin 1.3 consumers, you need to compile with
-api-version=1.3
https://kotlinlang.org/docs/compiler-reference.html#api-version-version (note that as of Kotlin 1.5,
-api-version=1.3
is deprecated)
m

mbonnin

06/21/2021, 9:07 PM
Does that also affect the metadata? I thought this was only about stdlib compatibility
e

ephemient

06/21/2021, 9:09 PM
even regardless of the metadata newer Kotlin will compile things assuming newer stdlib by default (e.g.
::
method references don't work across the version boundary without
-api-version
)
I believe metadata is supposed to have 1 version of compatibility now, so Kotlin 1.5 compiled code can run with Kotlin 1.4
not more than that, though
m

mbonnin

06/21/2021, 9:10 PM
Maybe as the metadata format stabilizes it will be more?
Can confirm
-api-version=1.3
doesn't help with metadata
So I guess when writing libraries being conservative is better...
...except when the K/N binary format changes where you need to update to the latest version for everyone that moved already 😬
t

tapchicoma

07/02/2021, 1:40 PM
@mbonnin hi, I am curious - consumers that are using Kotlin 1.4 also failed to consume your library compiled with Kotlin 1.5? 🤔
m

mbonnin

07/02/2021, 1:41 PM
I think Kotlin 1.4 is good, I had this with 1.3.72
t

tapchicoma

07/02/2021, 1:41 PM
m

mbonnin

07/02/2021, 1:43 PM
Thanks for the link! I guess asking users to update to 1.4 at this point is ok. I was mainly curious about the strategy there
t

tapchicoma

07/02/2021, 1:44 PM
yeah, personally, I am also got this knowledge recently 🤷‍♂️
👍 1
m

mbonnin

07/02/2021, 1:44 PM
I'll go with "always compile with latest Kotlin version (version n) and hope consumers have updated to version n - 1"
t

tapchicoma

07/02/2021, 1:49 PM
will repeat this information in this channel as well
👍 1