我从gradle.properties
读取带有点符号的属性时收到错误。为什么呢?
如果我使用version
代替build.version
,一切正常。
提前谢谢。
gradle.properties
build.version=2.0.1
的build.gradle
apply plugin: 'java'
task testProperties << {
println "***************** TEST **********************"
println build.version
println "*********************************************"
}
... $ gradle devTest
:devTest
***************** TEST **********************
:devTest FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '..../build.gradle' line: 50
* What went wrong:
Execution failed for task ':devTest'.
> Could not find property 'version' on task ':build'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or<br> --debug option to get more log output.
BUILD FAILED
gradle.properties
version=2.0.1
的build.gradle
apply plugin: 'java'
task testProperties << {
println "***************** TEST **********************"
println version
println "*********************************************"
}
... $ gradle devTest
:devTest
***************** TEST **********************
2.0.1
*********************************************
BUILD SUCCESSFUL
答案 0 :(得分:14)
You cannot use properties with a dot in this way because Groovy thinks it's a version
property of the build
instance. If you want a property to contain a dot then you should use it in the following way:
println rootProject.properties['build.version']
答案 1 :(得分:11)
访问属性的另一种方法是使用下面的语法
println "Version: ${project.'build.version'}"
答案 2 :(得分:1)
还有一个:
println property('build.version')
println "Version: ${property('build.version')}"
或
println ext['build.version']
println "Version: ${ext['build.version']}"