26

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 '*'
        }

1 Answer 1

37

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.