5

Is there a possibility to override build script property? I'm trying to build jar archive of my project and I want to specify 'version' via command line.

When I have 'version' property defined in my build.gradle (or gradle.properties), properties provided via commandline using -D/-P are not applied. Final jar is always built with version specified in build.gradle (or gradle.properties) and command line version property is ignored.

Thanks

Martinecko
  • 1,719
  • 4
  • 22
  • 35
  • 1
    You can use the elvis operator to reset the version variable within build.gradle (i.e. if a user doesn't pass variable "passed_version" to Gradle, then it'll pick variable "version" defined in build.gradle OTHERWISE, you can reset variable "version" using the value of "passed_version" from command line). – AKS Jul 25 '14 at 15:37

2 Answers2

2

The Gradle override plugin will help you with that. It allows for overriding any property exposed by any Gradle domain object (e.g. project properties, task properties, extension properties etc.).

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82
0

As explained in this answer: https://stackoverflow.com/a/57674847/5562284

Don't set the version in build.gradle file if you want to change it later on via cli.

Setting version in gradle.properties instead works.

nouveu
  • 162
  • 4
  • 9