Gradle def vs ext

What is the difference between using ext.varname and def varname . For instance. 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 just like

 task copyLicenses { ext.outDir = project.buildDir.absolutePath + '/reports/license/' doLast { copy { from 'licenses' into outDir include '*' } 
+6
source share
1 answer

The def keyword refers to Groovy and means that the variable has a local scope.

Using ext.outDir means that you are adding the outDir property to ExtraPropertiesExtension , think of it as if the project has a property map called ext , and you put your property on this map for later access.

+7
source

All Articles