I just got hit by `Module was compiled with an inc...
# library-development
m
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
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
Does that also affect the metadata? I thought this was only about stdlib compatibility
e
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
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
@mbonnin hi, I am curious - consumers that are using Kotlin 1.4 also failed to consume your library compiled with Kotlin 1.5? 🤔
m
I think Kotlin 1.4 is good, I had this with 1.3.72
t
m
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
yeah, personally, I am also got this knowledge recently 🤷‍♂️
👍 1
m
I'll go with "always compile with latest Kotlin version (version n) and hope consumers have updated to version n - 1"
t
will repeat this information in this channel as well
👍 1