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 '*'
        }
tim_yates
  • 167,322
  • 27
  • 342
  • 338
Kamil Roman
  • 973
  • 5
  • 15
  • 30

1 Answers1

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.

Community
  • 1
  • 1
AdamSkywalker
  • 11,408
  • 3
  • 38
  • 76