According to this page,
http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtensionAware.html
A lot of domain objects in Gradle are Extension aware, which means one can set extension properties on it by
‘ext.key = value’, or by other ways
The page says Configuration and Dependency are extension aware, and they should be, but they’re not,
not I can see.
Two pieces of evidence:
First, this code snippet should set a property on a dependency object
dependencies {
testCompile(group: 'junit', name: 'junit', version: '4.9') {
provided = true
ext.provided = true
}
}
But I cannot get the value from elsewhere.
task test
{ task ->
task.project.configurations.testCompile.each {
println it
println it.provided
println it.ext.provided
println it.hasProperty('provided')
}
}
Nothing shows up.
Although when i set
provided=true
, Gradle will warn me that dynamic properties are deprecated, use extension property, which by the way, dynamic properties don’t seem to work either.
Second, According to Gradle’s source code, the Configuration and Dependency object ARE NOT ExtensionAware. https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/artifacts/Dependency.java
So am I missing some points? Or this feature has not been implemented so far. I think this is an important feature.