Interface NamedDomainObjectContainer<T>
- Type Parameters:
T- The type of domain objects in this container.
- All Superinterfaces:
Collection<T>, org.gradle.util.Configurable<NamedDomainObjectContainer<T>>, DomainObjectCollection<T>, Iterable<T>, NamedDomainObjectCollection<T>, NamedDomainObjectSet<T>, Set<T>
- All Known Subinterfaces:
ArtifactTypeContainer, AuthenticationContainer, BuildTypeContainer, ConfigurationContainer, DistributionContainer, ExtensiblePolymorphicDomainObjectContainer<T>, FlavorContainer, IvyConfigurationContainer, NativeToolChainRegistry, PlatformContainer, PlayDistributionContainer, PolymorphicDomainObjectContainer<T>, PublicationContainer, Repositories, SourceSetContainer, TaskContainer
A named domain object container is a specialisation of NamedDomainObjectSet that adds the ability to create
instances of the element type.
Implementations may use different strategies for creating new object instances.
Note that a container is an implementation of SortedSet, which means that the container is guaranteed
to only contain elements with unique names within this container. Furthermore, items are ordered by their name.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAllows the container to be configured, creating missing objects as they are referenced.Creates a new item with the given name, adding it to this container.Creates a new item with the given name, adding it to this container, then configuring it with the given closure.Creates a new item with the given name, adding it to this container, then configuring it with the given action.maybeCreate(String name) Looks for an item with the given name, creating and adding it to this container if it does not exist.Defines a new object, which will be created when it is required.Defines a new object, which will be created and configured when it is required.Methods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface DomainObjectCollection
addLater, all, all, configureEach, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withTypeMethods inherited from interface NamedDomainObjectCollection
add, addAll, addRule, addRule, addRule, findByName, getAsMap, getAt, getByName, getByName, getByName, getCollectionSchema, getNamer, getNames, getRules, namedMethods inherited from interface NamedDomainObjectSet
findAll, matching, matching, withType
-
Method Details
-
create
Creates a new item with the given name, adding it to this container.- Parameters:
name- The name to assign to the created object- Returns:
- The created object. Never null.
- Throws:
InvalidUserDataException- if an object with the given name already exists in this container.
-
maybeCreate
-
create
Creates a new item with the given name, adding it to this container, then configuring it with the given closure.- Parameters:
name- The name to assign to the created objectconfigureClosure- The closure to configure the created object with- Returns:
- The created object. Never null.
- Throws:
InvalidUserDataException- if an object with the given name already exists in this container.
-
create
Creates a new item with the given name, adding it to this container, then configuring it with the given action.- Parameters:
name- The name to assign to the created objectconfigureAction- The action to configure the created object with- Returns:
- The created object. Never null.
- Throws:
InvalidUserDataException- if an object with the given name already exists in this container.
-
configure
Allows the container to be configured, creating missing objects as they are referenced.
TODO: example usage
- Specified by:
configurein interfaceorg.gradle.util.Configurable<T>- Parameters:
configureClosure- The closure to configure this container with- Returns:
- This.
-
register
@Incubating NamedDomainObjectProvider<T> register(String name, Action<? super T> configurationAction) throws InvalidUserDataException Defines a new object, which will be created and configured when it is required. An object is 'required' when the object is located using query methods such asNamedDomainObjectCollection.getByName(java.lang.String)or whenProvider.get()is called on the return value of this method.It is generally more efficient to use this method instead of
create(java.lang.String, org.gradle.api.Action)orcreate(java.lang.String), as those methods will eagerly create and configure the object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation and configuration until required.- Parameters:
name- The name of the object.configurationAction- The action to run to configure the object. This action runs when the object is required.- Returns:
- A
Providerthat whose value will be the object, when queried. - Throws:
InvalidUserDataException- If a object with the given name already exists in this project.- Since:
- 4.10
-
register
Defines a new object, which will be created when it is required. A object is 'required' when the object is located using query methods such asNamedDomainObjectCollection.getByName(java.lang.String)or whenProvider.get()is called on the return value of this method.It is generally more efficient to use this method instead of
create(java.lang.String), as that methods will eagerly create he object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation until required.- Parameters:
name- The name of the object.- Returns:
- A
Providerthat whose value will be the object, when queried. - Throws:
InvalidUserDataException- If a object with the given name already exists in this project.- Since:
- 4.10
-