Package org.gradle.api.artifacts

# Interface ConfigurationContainer

All Superinterfaces:
  `Collection<Configuration>`, `Configurable<NamedDomainObjectContainer<Configuration>>`, `DomainObjectCollection<Configuration>`, `DomainObjectSet<Configuration>`, `Iterable<Configuration>`, `NamedDomainObjectCollection<Configuration>`, `NamedDomainObjectContainer<Configuration>`, `NamedDomainObjectSet<Configuration>`, `Set<Configuration>`

@ServiceScope(org.gradle.internal.service.scopes.Scope.Project.class) public interface ConfigurationContainer extends NamedDomainObjectContainer<Configuration>

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

You can obtain a `ConfigurationContainer` instance by calling `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)

       plugins {
           id 'java' //so that I can use 'implementation', 'compileClasspath' configuration
       }

       dependencies {
           implementation 'org.slf4j:slf4j-api:2.0.17'
       }

       //copying all dependencies attached to 'compileClasspath' into a specific folder
       task copyAllDependencies(type: Copy) {
         //referring to the 'compileClasspath' configuration
         from configurations.compileClasspath
         into 'allLibs'
       }

An example showing how to declare and configure configurations

     plugins {
         id 'java' // so that I can use 'implementation', 'testImplementation' configurations
     }

     configurations {
       //adding a configuration:
       myConfiguration

       //adding a configuration that extends existing configuration:
       //(testImplementation was added by the java plugin)
       myIntegrationTestsCompile.extendsFrom(testImplementation)

       //configuring existing configurations not to put transitive dependencies on the compile classpath
       //this way you can avoid issues with implicit dependencies to transitive libraries
       compileClasspath.transitive = false
       testCompileClasspath.transitive = false
     }

Examples on configuring the resolution strategy - see docs for `ResolutionStrategy` Please see the Managing Dependency Configurations User Manual chapter for more information.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `NamedDomainObjectProvider<ConsumableConfiguration>`
  `consumable(String name)`
  Registers a new `ConsumableConfiguration` with an immutable role.
  `NamedDomainObjectProvider<ConsumableConfiguration>`
  `consumable(String name, Action<? super ConsumableConfiguration> action)`
  Registers a `ConsumableConfiguration` via `consumable(String)` and then configures it with the provided action.
  `NamedDomainObjectProvider<DependencyScopeConfiguration>`
  `dependencyScope(String name)`
  Registers a new `DependencyScopeConfiguration` with an immutable role.
  `NamedDomainObjectProvider<DependencyScopeConfiguration>`
  `dependencyScope(String name, Action<? super DependencyScopeConfiguration> action)`
  Registers a `DependencyScopeConfiguration` via `dependencyScope(String)` and then configures it with the provided action.
  `Configuration`
  `detachedConfiguration(Dependency... dependencies)`
  Creates a configuration, but does not add it to this container.
  `Configuration`
  `getAt(String name)`
  Locates an object by name, failing if there is no such object.
  `Configuration`
  `getByName(String name)`
  Locates an object by name, failing if there is no such object.
  `Configuration`
  `getByName(String name, Closure configureClosure)`
  Locates an object by name, failing if there is no such object.
  `Configuration`
  `getByName(String name, Action<? super Configuration> configureAction)`
  Locates an object by name, failing if there is no such object.
  `NamedDomainObjectProvider<ResolvableConfiguration>`
  `resolvable(String name)`
  Registers a `ResolvableConfiguration` with an immutable role.
  `NamedDomainObjectProvider<ResolvableConfiguration>`
  `resolvable(String name, Action<? super ResolvableConfiguration> action)`
  Registers a `ResolvableConfiguration` via `resolvable(String)` and then configures it with the provided action.

  ### Methods inherited from interface java.util.Collection

  `parallelStream, removeIf, stream, toArray`

  ### Methods inherited from interface org.gradle.api.DomainObjectCollection

  `addAllLater, addLater, all, all, configureEach, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectCollection

  `add, addAll, addRule, addRule, addRule, findByName, getAsMap, getCollectionSchema, getNamer, getNames, getRules, named, named, named, named`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectContainer

  `configure, create, create, create, maybeCreate, register, register`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectSet

  `findAll, matching, matching, named, withType`

  ### Methods inherited from interface java.util.Set

  `add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, spliterator, toArray, toArray`

- ## Method Details

  - ### getByName

    Configuration getByName(String name) throws UnknownConfigurationException
    Locates an object by name, failing if there is no such object.

    This operation is eager and will cause the returned element to be realized.

    Specified by:
      `getByName` in interface `NamedDomainObjectCollection<Configuration>`
    Parameters:
      `name` - The object name
    Returns:
      The object with the given name. Never returns null.
    Throws:
      `UnknownConfigurationException`

  - ### getAt

    Configuration getAt(String name) throws UnknownConfigurationException
    Locates an object by name, failing if there is no such object. This method is identical to `NamedDomainObjectCollection.getByName(String)`. You can call this method in your build script by using the groovy `[]` operator.

    This operation is eager and will cause the returned element to be realized.

    Specified by:
      `getAt` in interface `NamedDomainObjectCollection<Configuration>`
    Parameters:
      `name` - The object name
    Returns:
      The object with the given name. Never returns null.
    Throws:
      `UnknownConfigurationException`

  - ### getByName

    Configuration getByName(String name, @DelegatesTo(Configuration.class) Closure configureClosure) throws UnknownConfigurationException
    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.

    This operation is eager and will cause the returned element to be realized.

    Specified by:
      `getByName` in interface `NamedDomainObjectCollection<Configuration>`
    Parameters:
      `name` - The object name
      `configureClosure` - The closure to use to configure the object.
    Returns:
      The object with the given name, after the configure closure has been applied to it. Never returns null.
    Throws:
      `UnknownConfigurationException`

  - ### getByName

    Configuration getByName(String name, Action<? super Configuration> configureAction) throws UnknownConfigurationException
    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.

    This operation is eager and will cause the returned element to be realized.

    Specified by:
      `getByName` in interface `NamedDomainObjectCollection<Configuration>`
    Parameters:
      `name` - The object name
      `configureAction` - The action to use to configure the object.
    Returns:
      The object with the given name, after the configure action has been applied to it. Never returns null.
    Throws:
      `UnknownConfigurationException`

  - ### detachedConfiguration

    Configuration detachedConfiguration(Dependency... dependencies)
    Creates a configuration, but does not add it to this container.
    Parameters:
      `dependencies` - The dependencies of the configuration.
    Returns:
      The configuration.

  - ### resolvable

    @Incubating NamedDomainObjectProvider<ResolvableConfiguration> resolvable(String name)
    Registers a `ResolvableConfiguration` with an immutable role. Resolvable configurations are meant to resolve dependency graphs and their artifacts.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
    Returns:
      A provider which creates a new resolvable configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4

  - ### resolvable

    @Incubating NamedDomainObjectProvider<ResolvableConfiguration> resolvable(String name, Action<? super ResolvableConfiguration> action)
    Registers a `ResolvableConfiguration` via `resolvable(String)` and then configures it with the provided action.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
      `action` - The action to apply to the configuration.
    Returns:
      A provider which creates a new resolvable configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4

  - ### consumable

    @Incubating NamedDomainObjectProvider<ConsumableConfiguration> consumable(String name)
    Registers a new `ConsumableConfiguration` with an immutable role. Consumable configurations are meant to act as a variant in the context of Dependency Management and Publishing.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
    Returns:
      A provider which creates a new consumable configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4

  - ### consumable

    @Incubating NamedDomainObjectProvider<ConsumableConfiguration> consumable(String name, Action<? super ConsumableConfiguration> action)
    Registers a `ConsumableConfiguration` via `consumable(String)` and then configures it with the provided action.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
      `action` - The action to apply to the configuration.
    Returns:
      A provider which creates a new consumable configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4

  - ### dependencyScope

    @Incubating NamedDomainObjectProvider<DependencyScopeConfiguration> dependencyScope(String name)
    Registers a new `DependencyScopeConfiguration` with an immutable role. Dependency scope configurations collect dependencies, dependency constraints, and exclude rules to be used by both resolvable and consumable configurations.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
    Returns:
      A provider which creates a new dependency scope configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4

  - ### dependencyScope

    @Incubating NamedDomainObjectProvider<DependencyScopeConfiguration> dependencyScope(String name, Action<? super DependencyScopeConfiguration> action)
    Registers a `DependencyScopeConfiguration` via `dependencyScope(String)` and then configures it with the provided action.

    This operation is lazy, the returned element is NOT realized. A `lazy wrapper` is returned, allowing to continue to use it with other lazy APIs.

    Parameters:
      `name` - The name of the configuration to register.
      `action` - The action to apply to the configuration.
    Returns:
      A provider which creates a new dependency scope configuration.
    Throws:
      `InvalidUserDataException` - If a configuration with the given `name` already exists in this container.
    Since:
      8.4