I’ve been going through the gradle source code and the groovy language to understand this. But so far the answer has eluded me.
How does the implicit creation of objects in containers work in gradle? More specifically, implementations of NamedObjectContainer seem to have this magical ability to create objects if they don’t exist. I’m going to provide specific examples.
apply plugin: 'java' //so that I can use 'compile', 'testCompile' configurations
//adding a configuration:
//adding a configuration that extends existing configuration:
//(testCompile was added by the java plugin)
//configuring existing configurations not to put transitive dependencies on the compile classpath
//this way you can avoid issues with implicit dependencies to transitive libraries
compile.transitive = false
testCompile.transitive = false
The configuration myConfiguration is created implicitly here. An explicit creation would look like this.
I know the basics of the meta object protocol in groovy. I also know gradle uses AST transformation to get the convention mapping keys to be properties of the enclosing object. But none of that seems to explain what’s going on here.
The addRule method on NamedDomainObjectCollection can be used to do this. But I did a fairly thorough examination of where the method was being used and found that it doesn’t seem to be used to get this behavior.
@David_Karr It doesn’t seem likely. Those were the first things I checked.
These are the non-test files containing methodMissing. I explored most of them and they don’t seem to have much do with the question. And this would be a method call and not a property reference unless I’m terribly mistaken.