api / org.gradle.api / NamedDomainObjectContainer

NamedDomainObjectContainer

interface NamedDomainObjectContainer<T : Any> : NamedDomainObjectSet<T>, Configurable

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 java.util.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.

Parameters

- The type of domain objects in this container.

See Also
NamedDomainObjectSet

Functions

configure

abstract fun configure(configureClosure: Closure<Any>): NamedDomainObjectContainer<T>

Allows the container to be configured, creating missing objects as they are referenced.

TODO: example usage

create

abstract fun create(name: String): T

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

abstract fun create(name: String, configureClosure: Closure<Any>): T

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

abstract fun create(name: String, configureAction: Action<in T>): T

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

maybeCreate

abstract fun maybeCreate(name: String): T

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

Inherited Functions

findAll

abstract fun findAll(spec: Closure<Any>): MutableSet<T>

{@inheritDoc}

matching

abstract fun matching(spec: Spec<in T>): NamedDomainObjectSet<T>
abstract fun matching(spec: Closure<Any>): NamedDomainObjectSet<T>

{@inheritDoc}

withType

abstract fun <S : T> withType(type: Class<S>): NamedDomainObjectSet<S>

{@inheritDoc}

Extension Properties

creating

val <T : Any> NamedDomainObjectContainer<T>.creating: NamedDomainObjectContainerDelegateProvider<T>

Provides a property delegate that creates elements of the default collection type.

Extension Functions

creating

fun <T : Any> NamedDomainObjectContainer<T>.creating(configuration: T.() -> Unit): NamedDomainObjectContainerDelegateProvider<T>

Provides a property delegate that creates elements of the default collection type with the given configuration.

getting

fun <T : Any, U : T> NamedDomainObjectContainer<T>.getting(type: KClass<U>, configuration: U.() -> Unit): PolymorphicDomainObjectContainerGettingDelegateProvider<T, U>

Provides a property delegate that gets elements of the given type and applies the given configuration.

fun <T : Any, U : T> NamedDomainObjectContainer<T>.getting(type: KClass<U>): PolymorphicDomainObjectContainerGettingDelegate<T, U>

Provides a property delegate that gets elements of the given type.

invoke

operator fun <T : Any, C : NamedDomainObjectContainer<T>> C.invoke(configuration: NamedDomainObjectContainerScope<T>.() -> Unit): C

Allows the container to be configured, creating missing objects as they are referenced.

Inheritors

ArtifactTypeContainer

interface ArtifactTypeContainer : NamedDomainObjectContainer<ArtifactTypeDefinition>

Defines a set of known artifact types and related meta-data. This allows you to fine tune how dependency resolution handles artifacts of a specific type. Each entry in this container defines a particular artifact type, such as a JAR or an AAR, and some information about that artifact type.

BuildTypeContainer

interface BuildTypeContainer : NamedDomainObjectContainer<BuildType>

A container of BuildTypes.

ConfigurationContainer

interface ConfigurationContainer : NamedDomainObjectContainer<Configuration>

A ConfigurationContainer is responsible for declaring and managing configurations. See also Configuration.

You can obtain a ConfigurationContainer instance by calling org.gradle.api.Project#getConfigurations(), or using the configurations property in your build script.

The configurations in a container are accessible as read-only properties of the container, using the name of the configuration as the property name. For example:

 configurations.create('myConfiguration') configurations.myConfiguration.transitive = false 

A dynamic method is added for each configuration which takes a configuration closure. This is equivalent to calling #getByName(String, groovy.lang.Closure). For example:

 configurations.create('myConfiguration') configurations.myConfiguration { transitive = false } 
Examples An example showing how to refer to a given configuration by name in order to get hold of all dependencies (e.g. jars, but only)
 apply plugin: 'java' //so that I can use 'compile' configuration //copying all dependencies attached to 'compile' into a specific folder task copyAllDependencies(type: Copy) { //referring to the 'compile' configuration from configurations.compile into 'allLibs' } 
An example showing how to declare and configure configurations
 apply plugin: 'java' //so that I can use 'compile', 'testCompile' configurations configurations { //adding a configuration: myConfiguration //adding a configuration that extends existing configuration: //(testCompile was added by the java plugin) myIntegrationTestsCompile.extendsFrom(testCompile) //configuring existing configurations not to put transitive dependencies on the compile classpath //this way you can avoid issues with implicit dependencies to transitive libraries compile.transitive = false testCompile.transitive = false } 
Examples on configuring the resolution strategy - see docs for ResolutionStrategy Please see the Managing Dependency Configurations User Guide chapter for more information.

DistributionContainer

interface DistributionContainer : NamedDomainObjectContainer<Distribution>

A DistributionContainer manages a set of Distribution objects.

FlavorContainer

interface FlavorContainer : NamedDomainObjectContainer<Flavor>

A container of Flavors.

If no flavor is explicitly configured, will contain a single Flavor named 'default'. Any flavors explicitly configured will overwrite the default flavor.

IvyConfigurationContainer

interface IvyConfigurationContainer : NamedDomainObjectContainer<IvyConfiguration>

The set of IvyConfigurations that will be included in the IvyPublication. Being a org.gradle.api.NamedDomainObjectContainer, a IvyConfigurationContainer provides convenient methods for adding, querying, filtering, and applying actions to the set of IvyConfigurations.

 apply plugin: 'ivy-publish' def publication = publishing.publications.create("my-pub", IvyPublication) def configurations = publication.configurations configurations.create("extended", { extend "default"}) configurations.all { extend "base" } 

NamedDomainObjectContainerScope

class NamedDomainObjectContainerScope<T : Any> : NamedDomainObjectContainer<T>, PolymorphicDomainObjectContainer<T>

Receiver for NamedDomainObjectContainer configuration blocks.

PolymorphicDomainObjectContainer

interface PolymorphicDomainObjectContainer<T : Any> : NamedDomainObjectContainer<T>

A NamedDomainObjectContainer that allows to create domain objects with different types.

SourceSetContainer

interface SourceSetContainer : NamedDomainObjectContainer<SourceSet>, NamedDomainObjectSet<SourceSet>

A SourceSetContainer manages a set of SourceSet objects.