How to set project.version by passing version property on gradle command line?

前端 未结 6 881
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 03:55

I want to build JAR with self-defined version passed via command line, such as:

When I execute gradle build task like this:

gradle build -Pversion=1.         


        
6条回答
  •  自闭症患者
    2020-12-13 04:55

    You are not able to override existing project properties from command line, take a look here. So try to rename a version variable to something differing from version and set it with -P flag before command, like:

    gradle -PprojVersion=10.2.10 build 
    

    And then in your build.gradle

    if (project.hasProperty('projVersion')) {
      project.version = project.projVersion
    } else {
      project.version = '10.0.0'
    }
    

    Or as you did with ?: operator

提交回复
热议问题