kotlinx.serialization
kotlinx.serialization copied to clipboard
Add build-time check for Kotlin compiler version and kotlinx.serialization plugin version compatibility
What is your use-case and why do you need this feature?
Using incompatible versions between the Kotlin compiler and kotlinx.serialization plugin can result in obscure errors.
We recently encountered this in https://github.com/SebastianAigner/my-bird-app/issues/2, which is a demo project accompanying one of our official YouTube videos:
While the video was using Kotlin 1.8.20, the template used was since been updated to Kotlin 1.9. Because at the time of writing, the installation snippets in the kx.serialization README still point to 1.8.20, it's easy to accidentally copy the wrong installation snippet, and end up in situations where you get error messages like io.ktor.serialization.JsonConvertException: Illegal input: Expected class kotlinx.serialization.json.JsonObject as the serialized body of kotlinx.serialization.Polymorphic<List>, but had class kotlinx.serialization.json.JsonArray
.
Describe the solution you'd like
Build-time version equality check between the Kotlin and kx.serialization compiler plugin versions, and an error that contains information / instructions on how to address this (update the kx.serialization compiler plugin version).
(initially brought up internally at https://jetbrains.slack.com/archives/C2WQKN6JV/p1690982388347429).
I ran into a similar issue and couldn't find an update for it. Any progress on this?
That's exactly why I landed here, was going to rebuild the demo project "my-bird" with Sebastian's Youtube video and googled for the error
This should probably be done in the compiler plugin (which I believe still uses youtrack)
open -> gradle.properties and check Kotlin version Like this
kotlin.version=1.9.10
this version must same here kotlin("plugin.serialization") version "1.9.10"
@Ahtisham80005 If you want to check this in gradle this would need to be done a bit more complex than looking at gradle.properties (there is no requirement to use that). The bigger challenge is to ensure that the library version is high enough that the plugin supports it.