# How do you use objects in extensions?

**URL:** <https://discuss.gradle.org/t/how-do-you-use-objects-in-extensions/4023>\
**Category:** Old Forum Archive\
**Created:** [July 17, 2014, 12:52pm UTC](https://discuss.gradle.org/t/how-do-you-use-objects-in-extensions/4023 "2014-07-17T12:52:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GlennV](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@GlennV](https://discuss.gradle.org/u/GlennV)\
**Post date:** [July 17, 2014, 12:52pm UTC](https://discuss.gradle.org/t/how-do-you-use-objects-in-extensions/4023/1 "2014-07-17T12:52:00Z")

</div>

Hi,

The extension example in the “Writing Custom Plugins” chapter in the user guide shows how you can use an extension that contains String fields.

I’m trying to use an extension that contains a list of objects instead of simple fields, but I’m missing something.

My extension would be something like this:

```gradle
class MyExtension {
  List<MyMessage> messages
}
  class MyMessage {
  String text
  String[] targets
}

```

How would the extensions’ closure in my build.gradle look like? How does the info from the closure end up in my extension?

Kind regards,

Glenn

---

<div class="post-metadata">

**Author:** ![GlennV](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@GlennV](https://discuss.gradle.org/u/GlennV)\
**Post date:** [August 12, 2014, 7:58am UTC](https://discuss.gradle.org/t/how-do-you-use-objects-in-extensions/4023/2 "2014-08-12T07:58:00Z")

</div>

In case someone else is wondering about this, the [Gradle Beyond the Basics](http://chimera.labs.oreilly.com/books/1234000001741/index.html) book has a clear example. See the [Extensions](http://chimera.labs.oreilly.com/books/1234000001741/ch02.html#_extensions) section in chapter 2 “Custom Plugins”.

Basically, you have to use NamedDomainObjectContainer to define collections of your own domain objects.

Kind regards, Glenn
