Nesting NamedDomainObjectContainer

(noam) #1

Hi All,

Apologies if this has already been asked; how would I go about nesting NamedDomainObjectContainer objects? I use extensions for the configuration of a plugin that I’m writing, and part of that configuration is a collection of elements where in turn, each element may contain another collection.

For example:

extension {

collectionA {

elementA1 {

collectionB {




elementA2 {




I configure the extension and collection of ‘elementA’ by stating:

project.extensions.create(‘extension’, Extension)

project.extension.extensions.collectionA = project.container(ElementA)

But how can I define a NamedDomainObjectContainer for ‘collecteionB’ within each element in ‘collectionA’?


(noam) #2


After a little fiddling I’ve managed to achieve this by overriding the element creation process of ‘collectionA’ like so:

project.extension.extensions.collectionA = project.container(ElementA) {

def elementAExtension = project.extension.collectionA.extensions.create("$it", ElementA, “$it”.toString())

project.extension.collectionA."$it".extensions.‘collectionB’ = project.container(ElementB)



(Luke Daley) #3

Yep, that’s the way :slight_smile:

(Stanford Guillory) #4

I am really struggling to get an example of nested NamedDomainObjectContainers. Could someone provide a simple complete example? -Thanks

(noam) #5

I’ve got a sort-of-example in this POC plugin

(Stanford Guillory) #6

Thanks. I will have a look. Just to get unblocked, I changed my DSL from using a closure for the inner object to just mapping to a collection property on the main domain object. Not as cool, but I didn’t have any hair left to tear out.

Really would like to see some progress on documenting this process. It’s one of my few nits with Gradle at the moment.

Thanks again, Stanford S Guillory