Table of Contents
API Documentation: | ConfigurationContainer |
---|
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 ConfigurationContainer.getByName(java.lang.String, groovy.lang.Closure)
. For example:
configurations.create('myConfiguration')
configurations.myConfiguration {
transitive = false
}
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:1.7.26' } //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 | Description |
consumable(name) | Incubating Registers a new |
consumable(name, action) | Incubating Registers a |
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. |
dependencyScope(name) | Incubating Registers a new |
dependencyScope(name, action) | Incubating Registers a |
detachedConfiguration(dependencies) | Creates a configuration, but does not add it to this container. |
getAt(name) | Locates an object by name, failing if there is no such object. This method is identical to |
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) | Locates a object by name, without triggering its creation or configuration, failing if there is no such object. |
named(name, type) | Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. |
named(name, type, configurationAction) | Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider. |
named(name, configurationAction) | Locates a object by name, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider. |
named(nameFilter) | Incubating Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection. This method will NOT cause any pending objects in this container to be realized. |
register(name) | 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 |
register(name, configurationAction) | 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 |
resolvable(name) | Incubating Registers a |
resolvable(name, action) | Incubating Registers a |
NamedDomainObjectProvider
<ConsumableConfiguration
>
consumable
(String
name)
NamedDomainObjectProvider
<ConsumableConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
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.
NamedDomainObjectProvider
<ConsumableConfiguration
>
consumable
(String
name, Action
<? super ConsumableConfiguration
>
action)
NamedDomainObjectProvider
<ConsumableConfiguration
>Action
<? super ConsumableConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
Registers a ConsumableConfiguration
via ConfigurationContainer.consumable(java.lang.String)
and then
configures it with the provided action.
T
create
(String
name)
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.
NamedDomainObjectProvider
<DependencyScopeConfiguration
>
dependencyScope
(String
name)
NamedDomainObjectProvider
<DependencyScopeConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
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.
NamedDomainObjectProvider
<DependencyScopeConfiguration
>
dependencyScope
(String
name, Action
<? super DependencyScopeConfiguration
>
action)
NamedDomainObjectProvider
<DependencyScopeConfiguration
>Action
<? super DependencyScopeConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
Registers a DependencyScopeConfiguration
via ConfigurationContainer.dependencyScope(java.lang.String)
and then
configures it with the provided action.
Configuration
detachedConfiguration
(Dependency
...
dependencies)
Dependency
...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. This method is identical to NamedDomainObjectCollection.getByName(java.lang.String)
. You can call this method in your build script by using the groovy []
operator.
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. 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.
Configuration
getByName
(String
name, Action
<? super Configuration
>
configureAction)
Action
<? super Configuration
>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.
NamedDomainObjectProvider
<T
>
named
(String
name)
NamedDomainObjectProvider
<T
>Locates a object by name, without triggering its creation or configuration, failing if there is no such object.
NamedDomainObjectProvider
<S
>
named
(String
name, Class
<S
>
type)
NamedDomainObjectProvider
<S
>Class
<S
>Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
NamedDomainObjectProvider
<S
>
named
(String
name, Class
<S
>
type, Action
<? super S
>
configurationAction)
NamedDomainObjectProvider
<S
>Class
<S
>Action
<? super S
>Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
NamedDomainObjectProvider
<T
>
named
(String
name, Action
<? super T
>
configurationAction)
NamedDomainObjectProvider
<T
>Action
<? super T
>Locates a object by name, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
NamedDomainObjectCollection
<T
>
named
(Spec
<String
>
nameFilter)
NamedDomainObjectCollection
<T
>Spec
<String
>Note: This method is incubating and may change in a future version of Gradle.
Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection. This method will NOT cause any pending objects in this container to be realized.
NamedDomainObjectProvider
<T
>
register
(String
name)
NamedDomainObjectProvider
<T
>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 method will eagerly create the 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)
NamedDomainObjectProvider
<T
>Action
<? super T
>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.
NamedDomainObjectProvider
<ResolvableConfiguration
>
resolvable
(String
name)
NamedDomainObjectProvider
<ResolvableConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
Registers a ResolvableConfiguration
with an immutable role. Resolvable configurations
are meant to resolve dependency graphs and their artifacts.
NamedDomainObjectProvider
<ResolvableConfiguration
>
resolvable
(String
name, Action
<? super ResolvableConfiguration
>
action)
NamedDomainObjectProvider
<ResolvableConfiguration
>Action
<? super ResolvableConfiguration
>Note: This method is incubating and may change in a future version of Gradle.
Registers a ResolvableConfiguration
via ConfigurationContainer.resolvable(java.lang.String)
and then
configures it with the provided action.