Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle def vs ext

Tags:

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 '*'         } 
like image 272
Kamil Roman Avatar asked May 12 '16 11:05

Kamil Roman


People also ask

What is def in gradle?

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.

What does ext mean in gradle?

ext is shorthand for project. ext , and is used to define extra properties for the project object. (It's also possible to define extra properties for many other objects.) When reading an extra property, the ext. is omitted (e.g. println project. springVersion or println springVersion ).

Which are the two types of plugins in gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.


1 Answers

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.

like image 180
AdamSkywalker Avatar answered Nov 07 '22 01:11

AdamSkywalker