Gradle def vs ext [英] Gradle def vs ext

查看:139
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆