Collections
Gradle provides types for maintaining collections of objects, intended to work well to extends Gradle’s DSLs and provide useful features such as lazy configuration.
Collection hierarchy
All Gradle collection types extend from DomainObjectCollection<T>, which defines the core contract for live collections — including methods like configureEach(), withType(), matching(), all(), whenObjectAdded(), addLater(), and getElements().
DomainObjectCollection<T>
├── DomainObjectSet<T>
│ └── NamedDomainObjectSet<T>
└── NamedDomainObjectCollection<T>
├── NamedDomainObjectSet<T>
├── NamedDomainObjectList<T>
└── NamedDomainObjectContainer<T>
└── ExtensiblePolymorphicDomainObjectContainer<T>
NamedDomainObjectSet extends both DomainObjectSet and NamedDomainObjectCollection.
|
Available collections
These collection types are used for managing collections of objects, particularly in the context of build scripts and plugins:
-
DomainObjectSet<T>: Represents a set of objects of type T. This set does not allow duplicate elements, and you can add, remove, and query objects in the set. -
NamedDomainObjectSet<T>: A specialization ofDomainObjectSetwhere each object has a unique name associated with it. This is often used for collections where each element needs to be uniquely identified by a name. -
NamedDomainObjectList<T>: Similar toNamedDomainObjectSet, but represents a list of objects where order matters. Each element has a unique name associated with it, and you can access elements by index as well as by name. -
NamedDomainObjectContainer<T>: A container for managing objects of type T, where each object has a unique name. This container provides methods for adding, removing, and querying objects by name. -
ExtensiblePolymorphicDomainObjectContainer<T>: An extension ofNamedDomainObjectContainerthat allows you to define instantiation strategies for different types of objects. This is useful when you have a container that can hold multiple types of objects, and you want to control how each type of object is instantiated.