Gradle def vs ext [英] Gradle def vs ext
问题描述
使用 ext.varname
和 def varname
有什么区别。例如。下面的代码看起来是一样的:
任务copyLicenses {
def outDir = project.buildDir.absolutePath +' / reports / license /'
doLast {
copy {
from'licenses'
to outDir
include'*'
}
似乎与
<$ p完全相同$ p> 任务copyLicenses {
ext.outDir = project.buildDir.absolutePath +'/ reports / license /'
doLast {
copy {
from'licenses'
into outDir
include'*'
}
关键字 def
来自Groovy,意味着该变量具有 使用 使用 code> ext.outDir 表示您添加道具erty outDir
至 ExtraPropertiesExtension ,将其视为像项目具有名称 ext
的属性映射,然后将您的属性放在此映射中以供以后访问。
What is the difference between using ext.varname
and def varname
. E.g. the following code seems to work the same:
task copyLicenses {
def outDir = project.buildDir.absolutePath + '/reports/license/'
doLast {
copy {
from 'licenses'
into outDir
include '*'
}
seems to work exactly the same as
task copyLicenses {
ext.outDir = project.buildDir.absolutePath + '/reports/license/'
doLast {
copy {
from 'licenses'
into outDir
include '*'
}
Keyword def
comes from Groovy and means that variable has local scope.
Using ext.outDir
means that you add property outDir
to ExtraPropertiesExtension, think of it like project has a map of properties with name ext
, and you put your property in this map for later access.
这篇关于Gradle def vs ext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!