Groovy Documentation

org.gradle.api.artifacts.dsl
Interface DependencyHandler


interface DependencyHandler

A DependencyHandler is used to declare artifact dependencies. Artifact dependencies are grouped into configurations (see org.gradle.api.artifacts.Configuration), and a given dependency declarations is always attached to a single configuration.

To declare a specific dependency for a configuration you can use the following syntax:

 dependencies {
     configurationName dependencyNotation1, dependencyNotation2, ...
 }
 

or, to configure a dependency when it is declared, you can additionally pass a configuration closure:

 dependencies {
     configurationName dependencyNotation {
         configStatement1
         configStatement2
     }
 }
 

There are several supported dependency notations. These are described below. For each dependency declared this way, a Dependency object is created. You can use this object to query or further configure the dependency.

External Modules

There are 3 notations supported for declaring a dependency on an external module. One is a string notation:

configurationName "group:name:version:classifier"

The other is a map notation:

configurationName group: group:, name: name, version: version, classifier: classifier

In both notations, all properties, except name, are optional. External dependencies are represented using a org.gradle.api.artifacts.ExternalModuleDependency.

Client Modules

To add a client module to a configuration you can use the notation:

 configurationName module(moduleNotation) {
     module dependencies
 }
 
The module notation is the same as the dependency notations described above, except that the classifier property is not available. Client modules are represented using a org.gradle.api.artifacts.ClientModule.

Projects

To add a project dependency, you use the following notation

configurationName project(':someProject')

Project dependencies are represented using a org.gradle.api.artifacts.ProjectDependency.

Files

You can also add a dependency using a org.gradle.api.file.FileCollection:

configurationName files('a file')

File dependencies are represented using a org.gradle.api.artifacts.SelfResolvingDependency.

author:
Hans Dockter


Method Summary
Dependency add(java.lang.String configurationName, java.lang.Object dependencyNotation)

Adds a dependency to the given configuration.

Dependency add(java.lang.String configurationName, java.lang.Object dependencyNotation, Closure configureClosure)

Adds a dependency to the given configuration, and configures the dependency using the given closure/

 

Method Detail

add

public Dependency add(java.lang.String configurationName, java.lang.Object dependencyNotation)
Adds a dependency to the given configuration.
param:
configurationName The name of the configuration.
param:
dependencyNotation The dependency notation, in one of the notations decribed above.
return:
The dependency.


add

public Dependency add(java.lang.String configurationName, java.lang.Object dependencyNotation, Closure configureClosure)
Adds a dependency to the given configuration, and configures the dependency using the given closure/
param:
configurationName The name of the configuration.
param:
dependencyNotation The dependency notation, in one of the notations decribed above.
param:
configureClosure The closure to use to configure the dependency.
return:
The dependency.


 

Groovy Documentation