Dependency Constraint Handler
A DependencyConstraintHandler
is used to declare dependency constraints.
Dependency constraint notations
There are several supported dependency constraint notations. These are described below. For each dependency constraint declared this way, a DependencyConstraint object is created. You can use this object to query or further configure the dependency constraint.
You can also always add instances of DependencyConstraint directly:
configurationName(<instance>)
Dependency constraints can also be declared with a org.gradle.api.provider.Provider that provides any of the other supported dependency constraint notations.
External dependencies
There are two notations supported for declaring a dependency constraint on an external module. One is a string notation formatted this way:
configurationName("group:name:version")
The other is a map notation:
configurationName(group: group, name: name, version: version)
In both notations, all properties, except name, are optional.
plugins {
id("java-library") // so that we can use 'implementation', 'testImplementation' for dependency constraints
}
dependencies {
constraints {
//for dependencies found in artifact repositories you can use
//the string notation, e.g. group:name:version
implementation 'commons-lang:commons-lang:2.6'
testImplementation 'org.mockito:mockito:1.9.0-rc1'
//map notation:
implementation group: 'com.google.code.guice', name: 'guice', version: '1.0'
}
}
Project dependencies
To add a project dependency constraint, you use the following notation:
configurationName(project(":some-project"))
Since
4.5
Functions
Configures the dependency constraints.