pixel
pixel

Reputation: 26441

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.

Upvotes: 0

Views: 24

Answers (2)

pixel
pixel

Reputation: 26441

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.

Upvotes: 0

Eduard Tomek
Eduard Tomek

Reputation: 374

I would reccommend the following solution:

  1. Have a standard version of that plugin defined in gradle.properties file (some.version=1.0.0).
  2. Read it in the pluginManagement block
// kotlin
pluginManagement {
  val someVersion = extra["some.version"] as String
  println("========================================")
  println("some version is: $someVersion.")
  println("========================================")
}
  1. When necessary, you can change the property version by passing a value to the command line e.g.

./gradlew assemble -Psome.version=2.0.0

Upvotes: 0

Related Questions