I hit the following issue: <https://stackoverflow....
# gradle
r
I hit the following issue: https://stackoverflow.com/questions/67448034/module-was-compiled-with-an-incompatible-version-of-kotlin-the-binary-version I depend on a kotlin library (which I am the author of) which was built with kotiln 1.5.21 and gradle 7.1.1 in a project which uses Kotlin 1.3.72 and gradle 6.7 I guess the problem is gradle and not Kotlin (since updating gradle to 7.1.1 works). Is there a way to workaround this? e.g. set the metadata version somehow to 1.1.5 in the library? I don't want that users of my library are forced to update gradle if they use my library
v
You are not talking about build logic, do you? You are talking about actual production code. The Gradle version should not really be significant for that. But if you use the Kotlin Gradle Plugin 1.3.72 and thus use Kotlin 1.3.72 for your production code and then want to use a Kotlin 1.5-based library that can not work of course. That's just like if you want to use a Java 11 library in a Java 8 project. I guess with updaing Gradle you also used a newer Kotlin Gradle plugin, or you use
embeddedKotlin()
for whatever reason. But hard to tell without seeing your actual builds.
r
you mean kotlin is not follwing semver and 1.5 is not backward compatible with 1.3?
I did not run into the problem when the library was using kotlin 1.4.21
v
That's correct, Kotlin is not following semver, it is backwards compatible two versions and forward compatible one version. It is like Java 1.6 vs. Java 1.7 before they just dropped the
1.
in Java 8.
r
ah... I guess the default
languageVersion
changed in kotlin-gradle-plugin 1.5 from 1.3 to 1.4
v
For fully stable versions of the compiler the default binary compatibility protocol is the following:
- All binaries are backwards compatible, i.e. a newer compiler can read older binaries (e.g. 1.3 understands 1.0 through 1.2),
- Older compilers reject binaries that rely on new features (e.g. a 1.0 compiler rejects binaries that use coroutines).
- Preferably (but we can't guarantee it), the binary format is mostly forwards compatible with the next feature release, but not later ones (in the cases when new features are not used, e.g. 1.3 can understand most binaries from 1.4, but not 1.5).
r
I see
v
I think the default
languageVersion
is the version of the plugin you apply. In 1.3 it is 1.3, in 1.4 1.4, and in 1.5 1.5
But I'm not a Kotlin expert, mainly using it for build logic 🙂
r
it's probably the last bit where I was lucky so far:
the cases when new features are not used, e.g. 1.3 can understand most binaries from 1.4, but not 1.5
v
Probably, yes
r
what still surprises me is that upgrading gradle to 7.1.1 solved the problem as well (I did not update the kotlin version) - need to re-check why
👍 1
I guess I have reverted the update of the library, it fails now as well with 7.1.1. I am glad it's this way, I already faired a major upgrade of gradle could mean a major bump of the library
v
That would be really strange 😄