Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Kotlinx Serialization 1.8.0 with Kotlin 1.9.23 #2924

Open
nmggithub opened this issue Feb 8, 2025 · 6 comments
Open

Using Kotlinx Serialization 1.8.0 with Kotlin 1.9.23 #2924

nmggithub opened this issue Feb 8, 2025 · 6 comments

Comments

@nmggithub
Copy link

nmggithub commented Feb 8, 2025

Hello!

I am trying to use Kotlinx Serialization on a project that uses Kotlin 1.9.23. I've noticed that the most recent version, 1.8.0, seems to have a compile dependency on Kotlin 2.1.0: https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-core-jvm/1.8.0

Does this mean that I am unable to use it on versions previous to 2.1.0? Any help, advice, or knowledge, would be much appreciated.

Thank you!

EDIT: To clarify, when trying to use it in my 1.9.23 project, I get multiple build errors as the 2.1.0 library is clashing with everything else.

@nmggithub
Copy link
Author

OK, I think I figured out my confusion. The README.md says that:

Using Kotlin Serialization requires Kotlin compiler 1.4.0 or higher.
https://github.com/Kotlin/kotlinx.serialization/blob/v1.8.0/README.md?plain=1#L80

However, that looks like that stopped being true around v1.7.0:
b4bf182

Am I correct in believing that that line in the README.md is no longer accurate?

@sandwwraith
Copy link
Member

The phrase in the README refers to the fact that any kotlinx.serialization version requires at least 1.4.0. More recent versions require more recent compilers, and generally, the latest releases always depend on the latest Kotlin's.
I'm not sure it is possible to formulate the phrase clearer, since e.g. kotlinx-serialization 1.5.1 depends on Kotlin 1.8.21, but will (probably) work with 1.4. Although metadata version checks would likely prevent that.

@nmggithub
Copy link
Author

The phrase in the README refers to the fact that any kotlinx.serialization version requires at least 1.4.0. More recent versions require more recent compilers, and generally, the latest releases always depend on the latest Kotlin's. I'm not sure it is possible to formulate the phrase clearer, since e.g. kotlinx-serialization 1.5.1 depends on Kotlin 1.8.21, but will (probably) work with 1.4. Although metadata version checks would likely prevent that.

I see. It might be nice to have a compatibility table, at the very least.

Also, given what you mentioned about how more recent versions require more recent compilers, I would assume anyone stuck on older compilers just... can't use the more recent versions (and their features)? Or are there ways to make it work?

@pdvrieze
Copy link
Contributor

@nmggithub What the compiler plugin does is to generate the serializer for you. This generation changes somewhat between versions, and this means more recent compilers need more recent library versions. The other way around may (probably) work but could run into issues with some binary compatibility internal (@PublishedApi or optin) interfaces used by the generated serializers. There have not been fundamental large changes, but quite possibly smaller ones (and it is not a tested solution).

@nmggithub
Copy link
Author

@nmggithub What the compiler plugin does is to generate the serializer for you. This generation changes somewhat between versions, and this means more recent compilers need more recent library versions. The other way around may (probably) work but could run into issues with some binary compatibility internal (@PublishedApi or optin) interfaces used by the generated serializers. There have not been fundamental large changes, but quite possibly smaller ones (and it is not a tested solution).

I see. Thank you for the information. In any case, I still think a compatibility table would be much more informative than a vague "at least 1.4.0" (even if that statement is accurate).

@sandwwraith
Copy link
Member

I would assume anyone stuck on older compilers just... can't use the more recent versions (and their features)? Or are there ways to make it work?

That is generally true for any Kotlin library, see https://kotlinlang.org/docs/kotlin-evolution-principles.html#evolving-the-binary-format:

Preferably (but we can't guarantee it), the binary format is mostly forwards compatible with the next language release, but not later ones (in the cases when new features are not used, for example, 1.9 can understand most binaries from 2.0, but not 2.1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants