Hi. I found that the extension property delegates to the base extension. So the following are equal:
base.archivesName = 'xxx'
extension.archivesName = 'xxx'
I wonder the reason the extension property delegates to the base extension. I’m using Gradle 7.1.1 and Groovy DSL.
Here’s what I believe is happening;
The base
plugin creates an extension called base
, and it also configures a convention (now deprecated) of type DefaultBasePluginConvention
. This class contains a field named extension
which is a reference to the base
extension. Conventions work by exposing the POJO’s members as if they were part of the object that the convention is applied to (the project in this case). The fact that DefaultBasePluginConvention.extension
is private probably doesn’t matter because of groovy, or maybe just how the convention framework is implemented, that part I’m not sure of.
The ability to reference extension
should go away in whichever Gradle release removes the deprecated convention. For example, if you remove the base
convention you’ll see that extension
no longer works.
apply plugin: 'base'
println "base = ${base}"
println "extension = ${extension}"
println "conventions = ${convention.plugins}"
convention.plugins.remove 'base'
println " conventions = ${convention.plugins}"
println " base = ${base}"
println " extension = ${extension}" // fails with "unknown property"
> Configure project :
base = extension 'base'
extension = extension 'base'
conventions = [base:org.gradle.api.plugins.internal.DefaultBasePluginConvention@5df3257c]
conventions = [:]
base = extension 'base'
FAILURE: Build failed with an exception.
2 Likes