有没有办法在中定义全局变量 build.gradle
并让他们从任何地方访问。
我的意思是这样的
def variable = new Variable()
def method(Project proj) {
def value = variable.value
}
因为那样它告诉我它 cannot find property
。
我也想对这些方法做同样的事情。
我的意思是这样的
def methodA() {}
def methodB() { methodA() }
有没有办法在中定义全局变量 build.gradle
并让他们从任何地方访问。
我的意思是这样的
def variable = new Variable()
def method(Project proj) {
def value = variable.value
}
因为那样它告诉我它 cannot find property
。
我也想对这些方法做同样的事情。
我的意思是这样的
def methodA() {}
def methodB() { methodA() }
使用额外的属性。
ext.propA = 'propAValue'
ext.propB = propA
println "$propA, $propB"
def PrintAllProps(){
def propC = propA
println "$propA, $propB, $propC"
}
task(runmethod) << { PrintAllProps() }
运行 runmethod
打印:
gradle runmethod
propAValue, propAValue
:runmethod
propAValue, propAValue, propAValue
了解更多 Gradle额外属性在这里。
你应该能够从函数调用函数而不做任何特殊的事情:
def PrintMoreProps(){
print 'More Props: '
PrintAllProps()
}
结果是:
More Props: propAValue, propAValue, propAValue