Gradle def 与 ext

2023-12-21

使用有什么区别ext.varname and def varname。例如。下面的代码似乎工作相同:

task copyLicenses {
    def outDir = project.buildDir.absolutePath + '/reports/license/'

    doLast {
        copy {
            from 'licenses'
            into outDir
            include '*'
        }

似乎工作原理完全相同

task copyLicenses {
    ext.outDir = project.buildDir.absolutePath + '/reports/license/'

    doLast {
        copy {
            from 'licenses'
            into outDir
            include '*'
        }

Keyword def来自 Groovy,意味着变量有local https://stackoverflow.com/questions/184002/groovy-whats-the-purpose-of-def-in-def-x-0 scope.

Using ext.outDir意味着您添加属性outDir to 额外属性扩展 https://docs.gradle.org/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html,把它想象成项目有一个带有名称的属性图ext,然后您将您的财产放入此地图中以供以后访问。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Gradle def 与 ext 的相关文章

随机推荐