Search code examples
gradlecommand-linegradle-plugingradle-dependencies

How to temporarily override plugin version through command line in Gradle?


I want to override a plugin version to test if it behaves correctly with the new version. Is there a way to pass it through the command line?

My settings.gradle.kts:

pluginManagement {
    val myPluginVersion = "0.1.2"
    plugins {
        id("com.example.myplugin") version myPluginVersion
    }
}

It also should be possible for Dependabot to change this version permanently afterward.


Solution

  • I end up with the following solution:

    settings.gradle.kts:

        var myPluginVersion = "0.1.2"
        sbVersion = providers.gradleProperty("myPluginVersion").getOrElse(myPluginVersion)
        plugins {
            id("com.example.myplugin") version myPluginVersion
    

    The key is to divide simple version assignment and conditional logic into two separate lines.

    Then, Dependabot can parse the dependency version and bump it.