Configuration Container
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
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
}
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: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'
}
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
}
Properties
Provides a property delegate that creates elements of the default collection type.
Functions
Provides a property delegate that creates elements of the default collection type with the given configuration.
Locates an object by name and casts it to the expected type T.
Locates an object by name and casts it to the expected type T then configures it.
Locates an object by name and casts it to the expected type.
Locates an object by name and casts it to the expected type then configures it.
Provides a property delegate that gets elements of the given type.
Provides a property delegate that gets elements of the given type and applies the given configuration.
Allows the container to be configured via an augmented DSL.
Locates an object by name and type, without triggering its creation or configuration, failing if there is no such object.
Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.NamedDomainObjectCollection.named.
Configures an object by name and type, without triggering its creation or configuration, failing if there is no such object.
Allows a NamedDomainObjectCollection to be used as a property delegate.
Returns a collection containing the objects in this collection of the given type. The returned collection is live, so that when matching objects are later added to this collection, they are also visible in the filtered collection.
Returns a collection containing the objects in this collection of the given type. Equivalent to calling withType(type).all(configureAction)
.
Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.DomainObjectCollection.withType.
Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.DomainObjectSet.withType.
Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.NamedDomainObjectCollection.withType.
Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.NamedDomainObjectSet.withType.