Groovy Documentation

org.gradle.api.artifacts
[Java] Interface ConfigurationContainer

org.gradle.api.artifacts.ConfigurationContainer
  java.lang.Iterable
      org.gradle.api.NamedDomainObjectSet
          org.gradle.api.DomainObjectCollection
              org.gradle.api.NamedDomainObjectContainer
                  org.gradle.api.NamedDomainObjectCollection
                      java.util.Collection
All Superinterfaces:
java.lang.Iterable, NamedDomainObjectSet, DomainObjectCollection, NamedDomainObjectContainer, NamedDomainObjectCollection, java.util.Collection

public interface ConfigurationContainer
extends NamedDomainObjectContainer

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.add('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.add('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
Authors:
Hans Dockter


Method Summary
Configuration add(java.lang.String name)

Adds a configuration with the given name.

Configuration add(java.lang.String name, groovy.lang.Closure configureClosure)

Adds a configuration with the given name.

Configuration detachedConfiguration(Dependency... dependencies)

Creates a configuration, but does not add it to this container.

Configuration getAt(java.lang.String name)

{@inheritDoc}

Configuration getByName(java.lang.String name)

{@inheritDoc}

Configuration getByName(java.lang.String name, groovy.lang.Closure configureClosure)

{@inheritDoc}

 
Methods inherited from interface NamedDomainObjectContainer
configure, create, create
 
Methods inherited from interface org.gradle.util.Configurable
org.gradle.util.Configurable#configure(groovy.lang.Closure)
 
Methods inherited from interface NamedDomainObjectSet
findAll, matching, matching, withType
 
Methods inherited from interface NamedDomainObjectCollection
add, addAll, addRule, addRule, findByName, getAsMap, getAt, getByName, getByName, getNamer, getRules, matching, matching, withType
 
Methods inherited from interface DomainObjectCollection
all, all, allObjects, allObjects, findAll, findAll, getAll, matching, matching, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType, withType
 

Method Detail

add

public Configuration add(java.lang.String name)
Adds a configuration with the given name.
throws:
InvalidUserDataException when a configuration with the given name already exists in this container.
Parameters:
name - The name of the new configuration.
Returns:
The newly added configuration.


add

public Configuration add(java.lang.String name, groovy.lang.Closure configureClosure)
Adds a configuration with the given name. The given configuration closure is executed against the configuration before it is returned from this method.
throws:
InvalidUserDataException when a configuration with the given name already exists in this container.
Parameters:
name - The name of the new configuration.
configureClosure - The closure to use to configure the configuration.
Returns:
The newly added configuration.


detachedConfiguration

public 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.


getAt

public Configuration getAt(java.lang.String name)
{@inheritDoc}


getByName

public Configuration getByName(java.lang.String name)
{@inheritDoc}


getByName

public Configuration getByName(java.lang.String name, groovy.lang.Closure configureClosure)
{@inheritDoc}


 

Groovy Documentation