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 '*' }
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.
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 ).
There are two general types of plugins in Gradle, binary plugins and script plugins.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With