1

I want to override the project version of my gradle project
Usecase is :
build.gradle contains a default version like version = '1.0'
i want to update that to 1.2 through command line.
Like we have mvn versions:set in maven.

CrazyNerd
  • 63
  • 1
  • 8
  • 1
    I found this [solution](http://stackoverflow.com/questions/32717251/how-to-set-project-version-by-passing-version-property-on-gradle-command-line) in a prev question. I hope it helps. :) – LakiGeri Mar 04 '17 at 18:01
  • @LakiGeri i think that's a different use case where we are'nt overriding the version as it only sets the version and the reply says overriding isn't possible – CrazyNerd Mar 05 '17 at 05:29
  • all right. Actually I find this problem interesting, so i googled it, but i found nothing useful just this.. But I guess you googled it as well. – LakiGeri Mar 05 '17 at 07:29
  • @LakiGeri yes i tried writing various tasks as well but once version is set its not changing. – CrazyNerd Mar 05 '17 at 08:29

1 Answers1

1

build.gradle

task myTask {
    if (project.hasProperty("myVersion")) {
        project.setVersion(myVersion)
        println "I have the build version: " + version
    }
}

execute:

gradle mytask -PmyVersion=1.2

result:

I have the build version: 1.2
:myTask UP-TO-DATE

BUILD SUCCESSFUL