Configuration Container
@ServiceScope(value = Project::class )
A ConfigurationContainer is responsible for declaring and managing configurations. See also Configuration.
You can obtain a ConfigurationContainer instance by calling 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
Content copied to clipboard
A dynamic method is added for each configuration which takes a configuration closure. This is equivalent to calling getByName. For example:
configurations.create('myConfiguration')
configurations.myConfiguration {
transitive = false
}
Content copied to clipboard
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'
}
Content copied to clipboard
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
}
Content copied to clipboard
Functions
Link copied to clipboard
Adds any of the given objects to the collection that do not have the same name as any existing element.
Link copied to clipboard
Link copied to clipboard
Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
Executes the given action against all objects in this collection, and any objects subsequently added to this collection.
Link copied to clipboard
Configures each element in this collection using the given action, as each element is required.
Link copied to clipboard
Registers a new ConsumableConfiguration with an immutable role.
abstract fun consumable(name: String, action: Action<in ConsumableConfiguration>): NamedDomainObjectProvider<ConsumableConfiguration>
Registers a ConsumableConfiguration via consumable and then configures it with the provided action.
Link copied to clipboard
Link copied to clipboard
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.
Link copied to clipboard
Registers a new DependencyScopeConfiguration with an immutable role.
abstract fun dependencyScope(name: String, action: Action<in DependencyScopeConfiguration>): NamedDomainObjectProvider<DependencyScopeConfiguration>
Registers a DependencyScopeConfiguration via dependencyScope and then configures it with the provided action.
Link copied to clipboard
Creates a configuration, but does not add it to this container.
Link copied to clipboard
Disallows further structural modifications to this collection.
Link copied to clipboard
Locates an object by name, returning null if there is no such object.
Link copied to clipboard
Locates an object by name, failing if there is no such object.
Link copied to clipboard
abstract fun getByName(name: String, @DelegatesTo(value = Configuration::class ) configureClosure: Closure): Configuration
Locates an object by name, failing if there is no such object.
Link copied to clipboard
Provides access to the schema of all created or registered named domain objects in this collection.
Link copied to clipboard
Returns a collection which contains the objects in this collection which meet the given closure specification.
Returns a collection which contains the objects in this collection which meet the given specification.
Link copied to clipboard
Looks for an item with the given name, creating and adding it to this container if it does not exist.
Link copied to clipboard
Locates a object by name, failing if there is no such object.
Returns a collection containing the objects with names matching the provided filter.
abstract fun <S : T?> named(name: String, type: Class<S>, configurationAction: Action<in S>): NamedDomainObjectProvider<S>
Locates a object by name and type, failing if there is no such object.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Registers a ResolvableConfiguration with an immutable role.
abstract fun resolvable(name: String, action: Action<in ResolvableConfiguration>): NamedDomainObjectProvider<ResolvableConfiguration>
Registers a ResolvableConfiguration via resolvable and then configures it with the provided action.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Adds a closure to be called when an object is added to this collection.
Adds an
Action to be executed when an object is added to this collection.Link copied to clipboard
Adds a closure to be called when an object is removed from this collection.
Adds an
Action to be executed when an object is removed from this collection.Link copied to clipboard
abstract fun <S : T?> withType(type: Class<S>, @DelegatesTo(genericTypeIndex = 0 ) configureClosure: Closure): DomainObjectCollection<S>
abstract fun <S : T?> withType(type: Class<S>, configureAction: Action<in S>): DomainObjectCollection<S>
Returns a collection containing the objects in this collection of the given type.