This chapter is currently under construction.
For all the details of artifact handling see Chapter 22, Artifact Management.
This chapter introduces some of the basics of artifact handling in Gradle.
Artifacts are grouped into configurations. A configuration is simply a set of files with a name. You can use them to declare the external dependencies your project has, or to declare the artifacts which your project publishes.
To define a configuration:
To access a configuration:
Example 5.2.
build.gradle
println configurations.compile.name println configurations['compile'].name
To configure a configuration:
Example 5.3.
build.gradle
configurations {
compile {
description = 'compile classpath'
transitive = true
}
runtime {
extendsFrom compile
}
}
configurations.compile {
description = 'compile classpath'
}Artifacts are stored in repositories.
To use maven central repository:
To use a local directory:
You can also use any Ivy resolver. You can have multiple repositories.
To access a repository:
Example 5.6.
build.gradle
println repositories.localRepository.name
println repositories['localRepository'].nameTo configure a repository:
Example 5.7.
build.gradle
repositories {
localRepository {
addArtifactPattern(file('lib').absolutePath + '/[name]/[revision]/[name]-[revision].[ext]')
}
}
repositories.localRepository {
addArtifactPattern(file('lib').absolutePath + '/[name]/[revision]/[name]-[revision].[ext]')
}To define an external dependency, you add a dependency to a configuration:
Example 5.8.
build.gradle
configurations {
compile
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
}
group and version are optional
TBD - configuring an external dependency
To use the external dependencies of a configuration:
Example 5.9.
build.gradle
task listJars << {
configurations.compile.each { File file -> println file.name }
}Configurations are contained in a
ConfigurationContainer
.
Each configuration implements the
Configuration
.