ext 和代码块在 gradle 文件中的含义 [英] ext and code block's meaning in the gradle file
问题描述
ext {
springVersion = "3.1.0.RELEASE"
emailNotification = "build@master.org"
}
以上代码是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 = "build@master.org"
}
但运行该代码发生以下错误.
but run that code below 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
或 printlnspring版本
).从方法内部也是如此.声明一个名为 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
.
这篇关于ext 和代码块在 gradle 文件中的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!