NamedDomainObjectContainer

API Documentation:NamedDomainObjectContainer

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.

Properties

No properties

Methods

MethodDescription
create(name)

Creates a new item with the given name, adding it to this container.

create(name, configureClosure)

Creates a new item with the given name, adding it to this container, then configuring it with the given closure.

create(name, configureAction)

Creates a new item with the given name, adding it to this container, then configuring it with the given action.

getByName(name)

Locates an object by name, failing if there is no such object.

getByName(name, configureClosure)

Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.

getByName(name, configureAction)

Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.

maybeCreate(name)

Looks for an item with the given name, creating and adding it to this container if it does not exist.

named(name)
Incubating

Locates a object by name, without triggering its creation or configuration, failing if there is no such object.

register(name)
Incubating

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 as NamedDomainObjectCollection.getByName(java.lang.String) or when Provider.get() is called on the return value of this method.

register(name, configurationAction)
Incubating

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 as NamedDomainObjectCollection.getByName(java.lang.String) or when Provider.get() is called on the return value of this method.

Script blocks

No script blocks

Method details

T create(String name)

Creates a new item with the given name, adding it to this container.

T create(String name, Closure configureClosure)

Creates a new item with the given name, adding it to this container, then configuring it with the given closure.

T create(String name, Action<? super T> configureAction)

Creates a new item with the given name, adding it to this container, then configuring it with the given action.

T getByName(String name)

Locates an object by name, failing if there is no such object.

T getByName(String name, Closure configureClosure)

Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.

T getByName(String name, Action<? super T> configureAction)

Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.

T maybeCreate(String name)

Looks for an item with the given name, creating and adding it to this container if it does not exist.

Note: This method is incubating and may change in a future version of Gradle.

Locates a object by name, without triggering its creation or configuration, failing if there is no such object.

Note: This method is incubating and may change in a future version of Gradle.

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 as NamedDomainObjectCollection.getByName(java.lang.String) or when Provider.get() is called on the return value of this method.

It is generally more efficient to use this method instead of NamedDomainObjectContainer.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.

NamedDomainObjectProvider<T> register(String name, Action<? super T> configurationAction)

Note: This method is incubating and may change in a future version of Gradle.

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 as NamedDomainObjectCollection.getByName(java.lang.String) or when Provider.get() is called on the return value of this method.

It is generally more efficient to use this method instead of NamedDomainObjectContainer.create(java.lang.String, org.gradle.api.Action) or NamedDomainObjectContainer.create(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.