Skip to content

AddTomlVersionCatalogPlugin

pl.allegro.tech.allwrite.recipes.gradle.AddTomlVersionCatalogPlugin

Adds or updates a plugin entry in gradle/libs.versions.toml and applies the corresponding catalog alias to build.gradle and build.gradle.kts plugin blocks. Library entries and their version.ref values are not changed.

When the plugin ID is already present under another alias, the recipe reuses that alias. It fails rather than overwriting an alias that belongs to a different plugin or guessing which alias to use when the same plugin ID appears more than once.

Options:

Name Type Required Description
pluginName String Yes Version catalog alias for the plugin.
pluginId String Yes Gradle plugin ID.
pluginVersion String No Literal fallback version for a missing [versions].pluginName entry.
applyToModulesWithPluginId String No Only apply the alias to build files that apply this plugin ID. The catalog changes only when a match exists.

pluginVersion is only used when the version catalog does not already define [versions].pluginName; existing version values are preserved. The plugin entry always uses pluginName as its version.ref.

Before (with pluginName = "example", pluginId = "com.example.plugin", and pluginVersion = "1.2.3"):

[libraries]
example-bom = { group = "com.example", name = "example-bom", version.ref = "example" }

After:

[libraries]
example-bom = { group = "com.example", name = "example-bom", version.ref = "example" }

[versions]
example = "1.2.3"

[plugins]
example = { id = "com.example.plugin", version.ref = "example" }
plugins {
    alias(libs.plugins.example)
}

When applyToModulesWithPluginId is configured, build files are checked independently. For example, with applyToModulesWithPluginId = "application":

Before:

app/build.gradle.kts

plugins {
    application
}

lib/build.gradle.kts

plugins {
    id("java-library")
}

After:

app/build.gradle.kts

plugins {
    application
    alias(libs.plugins.example)
}

lib/build.gradle.kts

plugins {
    id("java-library")
}

The shared version catalog receives the example plugin entry because the application module matched. The library module remains unchanged.