kotlingradle

Use version catalog for the kotlin serialization plugin in gradle build


Currently I added the Kotlin serialization plugin in Gradle like this:

plugins {
   kotlin("plugin.serialization") version "2.0.10"
}

I would like to use the version catalog for specifying the plugin along with the Kotlin version. But I can not figure out how to do so.

I tried to do the following but it did not work:

versions.toml:

[versions]
kotlin = "2.0.0"

[plugins]
serialization = { id = "serialization", version.ref = "kotlin" }
// I also tried: id = "plugin.serialization"

Gradle:

plugins {
    alias(libs.plugins.serialization)
}

Btw, If I would not find a way to do this I would at least like to be able to do something like this:

plugins {
   kotlin("plugin.serialization") version libs.plugins.serialization.toString()
}
``

Solution

  • You need this in your libs.versions.toml file:

    [plugins]
    serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }