kotlinx.serialization
kotlinx.serialization copied to clipboard
Cannot properly install KxS
Describe the bug
Based on https://github.com/JetBrains/intellij-platform-plugin-template, I'm trying to use kotlinx.serialization for a plugin. However, despite multiple attempts with different configurations, I cannot make the plugin to get installed properly: my setup seems to be using an old KxS bundled with Kotlin instead of the one I'm telling it to use.
I tried entirely cleaning my Gradle cache, restarting the IDE, re-building from scratch without cache, hardcoding the dependencies in my kts file... (I've been trying for multiple previous Gradle versions too)
To Reproduce
Use this libs.versions.toml (truncated for brevity):
[versions]
kotlin = "1.9.24"
serializationJson = "1.6.3"
[libraries]
serializationJson = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "serializationJson" }
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
serialization = { id = "plugin.serialization", version.ref = "kotlin" }
and this build.gradle.kts (truncated for brevity):
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
kotlin(libs.plugins.serialization.get().pluginId) version libs.versions.kotlin // Kotlin Serialization support
}
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
implementation(libs.serializationJson)
}
kotlin {
jvmToolchain(11)
}
Expected behavior
To use the version of the library I want it to use (1.6.3 here)
Environment
- Kotlin version: [e.g. 1.3.30] 1.9.24
- Library version: [e.g. 0.11.0] 1.9.24/1.6.3
- Kotlin platforms: [e.g. JVM, JS, Native or their combinations] JVM
- Gradle version: [e.g. 4.10] 8.8
- IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4] IDEA U 2024.1.2
- Other relevant context [e.g. OS version, JRE version, ... ] macOS 14.5, JDK 11
As far as I understand, you're writing a plugin for IntelliJ. It indeed has some bundled version of serialization, which may not be up-to-date. I suggest you create a ticket in the Intellij platform subsystem (https://youtrack.jetbrains.com/issues/IJPL); maybe they have a solution, as I am not directly involved in it. What you can do now, perhaps, is to use the Shadow plugin to re-package a required library version into your plugin with a different package.
Yep you got it correctly! Sorry for being unclear.
What's the Shadow plugin? Do you think I can try to use the Gradle constraints API to override the bundled dep?
But yeah, I'll create a ticket, thanks!
Edit: opened!
@WarningImHack3r See https://imperceptiblethoughts.com/shadow/introduction/#benefits-of-shadow and https://imperceptiblethoughts.com/shadow/configuration/relocation/#filtering-relocation
@sandwwraith ok that looks a bit like what I meant to do with Gradle; I'm going to try that filtering thing while the ticket's being processed! Thanks
@sandwwraith I can't manage to make it work:
// build.gradle.kts
...
tasks {
shadowJar {
relocate("kotlinx.serialization.json", "a") {
exclude("kotlinx.serialization.json.*")
}
}
...
This does absolutely nothing
Closing in favor of https://youtrack.jetbrains.com/issue/IJPL-156386/Override-the-bundled-kotlinx.serialization-plugin
(I'd close as won't fix instead to not mislead people into thinking the problem is solved)