Hi,
while it’s clear to me how to support a map of custom objects in Gradle DSL using a NamedDomainObjectContainer, I can’t find any way to support a list of anonymous custom objects.
Here’s what I’d like to have in my DSL:
identifiers = [
{
position = 'BUILD'
qualifier = 'branch'
value = '123'
},
{
position = 'BUILD'
qualifier = 'commit'
value = '456'
},
{
position = 'BUILD'
qualifier = 'timestamp'
value = '789'
}
]
and here’s the java snippet from my extension:
private final ListProperty<Identifier> identifiers = getObjectfactory().listProperty(Identifier.class);
public ListProperty<Identifier> getIdentifiers() {
return identifiers;
}
public void identifiers(Action<? super ListProperty<Identifier>> configurationAction) {
configurationAction.execute(identifiers); // this is invoked but does nothing
}
where Identifier is the class of the items.
I always get an exception because the closure has some unknown type of object. But if I replace the DSL block with this:
identifiers {[
{
position = 'BUILD'
qualifier = 'branch'
value = '123'
},
{
position = 'BUILD'
qualifier = 'commit'
value = '456'
},
{
position = 'BUILD'
qualifier = 'timestamp'
value = '789'
}
]}
I have no exception, but still the list is not parsed.
Any help? Is it even possible to parse a list of custom objects?