kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Add build-time check for Kotlin compiler version and kotlinx.serialization plugin version compatibility

Open SebastianAigner opened this issue 1 year ago • 6 comments

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).

SebastianAigner avatar Aug 03 '23 11:08 SebastianAigner

(initially brought up internally at https://jetbrains.slack.com/archives/C2WQKN6JV/p1690982388347429).

SebastianAigner avatar Aug 03 '23 11:08 SebastianAigner

I ran into a similar issue and couldn't find an update for it. Any progress on this?

ibrahimethemsen avatar Sep 06 '23 09:09 ibrahimethemsen

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

smartkanak avatar Sep 09 '23 22:09 smartkanak

This should probably be done in the compiler plugin (which I believe still uses youtrack)

pdvrieze avatar Sep 11 '23 08:09 pdvrieze

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 avatar Sep 16 '23 23:09 Ahtisham80005

@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.

pdvrieze avatar Sep 17 '23 14:09 pdvrieze