Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.33k stars 618 forks source link

Cannot properly install KxS #2710

Open WarningImHack3r opened 3 months ago

WarningImHack3r commented 3 months ago

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

sandwwraith commented 3 months ago

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.

WarningImHack3r commented 3 months ago

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!

sandwwraith commented 3 months ago

@WarningImHack3r See https://imperceptiblethoughts.com/shadow/introduction/#benefits-of-shadow and https://imperceptiblethoughts.com/shadow/configuration/relocation/#filtering-relocation

WarningImHack3r commented 3 months ago

@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

WarningImHack3r commented 3 months ago

@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