如何通过在gradle命令行上传递版本属性来设置project.version? [英] How to set project.version by passing version property on gradle command line?
问题描述
我想通过命令行传递自定义的版本来构建JAR,例如:
当我执行像这样的gradle构建任务时:
gradle build -Pversion = 1.0
应该生成myproject-1.0.jar。
我已经尝试将以下行添加到 build.gradle ,但它不起作用:
version = project.hasProperty('version')? project ['version']:'10 .0.0'
您无法从命令行覆盖现有项目属性,请查看此处。因此,尝试将版本变量重命名为不同于版本的版本,并在命令之前将其设置为 -P
标志,如:
gradle -PprojVersion = 10.2.10 build
然后在您的build.gradle
if(project.hasProperty('projVersion')){
project.version = project .projVersion
} else {
project.version = '10 .0.0'
}
或者像你所做的那样::operator
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.0
myproject-1.0.jar should be generated.
I have tried adding the line below to the build.gradle, but it did not work:
version = project.hasProperty('version') ? project['version'] : '10.0.0'
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
这篇关于如何通过在gradle命令行上传递版本属性来设置project.version?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!