This may be a Groovy question, but I discovered it in the context of Gradle, so I’m wondering if someone can help me understand. Given this single Gradle script:
apply plugin: 'java'
configurations.runtime ( { println "hello" } )
Gradle will output “hello” when executed. Why? The Configuration interface has no methods that accept a closure. Can someone explain to me how this works?
‘configurations’ is an instance of ‘ConfigurationHandler’ and uses Groovy meta-programming to allow you to say things like ‘configurations.runtime { extendsFrom compile }’. In other words, ‘configurations’ provides dynamic methods that accept a closure argument.
Fascinating; thanks, Peter. Now, I looked for the ConfigurationHandler class in the source–I found it it some old copies, but not in the latest tree. Can you point me to where the Configuration class gets wrapped? I’d like to understand this further.
Sorry it’s ‘ConfigurationContainer’, not ‘ConfigurationHandler’. Dynamic methods with closure argument are handled by ‘DefaultNamedDomainObjectCollection.invokeMethod()’.