# Configurations and closures

**URL:** <https://discuss.gradle.org/t/configurations-and-closures/6038>\
**Category:** Old Forum Archive\
**Created:** [September 18, 2012, 1:38pm UTC](https://discuss.gradle.org/t/configurations-and-closures/6038 "2012-09-18T13:38:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Nelson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ryan_nelson/32/381_2.png) [@Ryan\_Nelson](https://discuss.gradle.org/u/Ryan_Nelson)\
**Post date:** [September 18, 2012, 1:38pm UTC](https://discuss.gradle.org/t/configurations-and-closures/6038/1 "2012-09-18T13:38:00Z")

</div>

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:

```gradle
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?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [September 18, 2012, 2:57pm UTC](https://discuss.gradle.org/t/configurations-and-closures/6038/2 "2012-09-18T14:57:00Z")

</div>

‘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.

---

<div class="post-metadata">

**Author:** ![Ryan\_Nelson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ryan_nelson/32/381_2.png) [@Ryan\_Nelson](https://discuss.gradle.org/u/Ryan_Nelson)\
**Post date:** [September 18, 2012, 7:03pm UTC](https://discuss.gradle.org/t/configurations-and-closures/6038/3 "2012-09-18T19:03:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [September 18, 2012, 7:13pm UTC](https://discuss.gradle.org/t/configurations-and-closures/6038/4 "2012-09-18T19:13:00Z")

</div>

Sorry it’s ‘ConfigurationContainer’, not ‘ConfigurationHandler’. Dynamic methods with closure argument are handled by ‘DefaultNamedDomainObjectCollection.invokeMethod()’.

---

<div class="post-metadata">

**Author:** ![Ryan\_Nelson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ryan_nelson/32/381_2.png) [@Ryan\_Nelson](https://discuss.gradle.org/u/Ryan_Nelson)\
**Post date:** [September 19, 2012, 4:14am UTC](https://discuss.gradle.org/t/configurations-and-closures/6038/5 "2012-09-19T04:14:00Z")

</div>

Great! Thanks.
