Search code examples
gradletoml

Cannot declare the "java-library" Gradle plugin via "alias" from "libs.versions.toml"


Is alias(libs.plugins.java.library) possible?

I have a bizarre desire to declare my Gradle modules' plugin dependencies via alias-ing them all from the lib.versions.toml catalog for the sake of consistency. Currently the java-library core Gradle plugin is declared as id("java-library"), but I would like it to be alias(libs.plugins.java.library). However...

When I omit the version or put "":

[plugins]
# java-library = { id = "java-library" }
java-library = { id = "java-library", version = "" }

I get the error plugin version '' is invalid: cannot be null or empty.

When I put "1", or "_", or anything non-blank:

[plugins]
# java-library = { id = "java-library", version = "1" }
java-library = { id = "java-library", version = "_" }

I get the error Plugin 'java-library' is a core Gradle plugin, which cannot be specified with a version number. Such plugins are versioned as part of Gradle. Please remove the version number from the declaration.

Is there any way to alias this plugin? If not, what is the next best workaround to abstract away the magic string ID?


Solution

  • The closest I could get until now (with Gradle 8.4) was something like this:

    libs.versions.toml

    [plugins]
    java-library = { id = "java-library" }
    

    build.gradle.kts

    plugins {
        id(libs.plugins.java.library.get().pluginId)
    }