问题描述
ext {
springVersion = "3.1.0.RELEASE"
emailNotification = "[email protected]"
}
以上代码是build.gradle的代码段
Above code is the snippet of build.gradle
我知道可以使用{}闭包参数来调用ext方法.这是正确的?所以我认为gradle正在访问springVersion和emailNotification.我将使用以下代码验证我的假设
I understand that call ext method with { } closure parameter.it's right?So I think gradle is accessing springVersion and emailNotification.I'm gonna verify my assumption with below code
def ext(data) {
println data.springVersion
}
ext {
springVersion = "3.1.0.RELEASE"
emailNotification = "[email protected]"
}
但是运行该代码下方发生错误.
but run that codebelow Error occured.
groovy.lang.MissingPropertyException: No such property: springVersion for class: Test
您具体解释ext和代码块吗?
do you explain ext and code block specifically?
推荐答案
ext
是project.ext
的简写,用于为project
对象定义额外属性. (也可以为许多其他对象定义额外的属性.)读取额外的属性时,将省略ext.
(例如println project.springVersion
或println springVersion
).在方法内部也是如此.声明一个名为ext
的方法是没有意义的.
ext
is shorthand for project.ext
, and is used to define extra properties for the project
object. (It's also possible to define extra properties for many other objects.) When reading an extra property, the ext.
is omitted (e.g. println project.springVersion
or println springVersion
). The same works from within methods. It does not make sense to declare a method named ext
.
这篇关于grad和gradle文件中的ext和code block的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!