# DependencyConstraintHandler

@ServiceScope(value = Project::class)
interface DependencyConstraintHandler(source)

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

Module dependencies are declared using single-string notation, where each coordinate is separated by a colon. All properties, except the name, are optional. `configurationName("group:name:version")`

    plugins {
        id("java-library")
    }

    dependencies {
        constraints {
            // Declaring constraints on module components
            // Coordinates are separated by a single colon -- group:name:version
            implementation("org.apache.commons:commons-lang3:3.17.0")
            testImplementation("org.mockito:mockito-core:5.18.0")
        }
    }

Content copied to clipboard

### Project dependencies

To add a project dependency constraint, you use the following notation:

`configurationName(project(":some-project"))`

#### Since

4.5

## Functions

add
Link copied to clipboard
abstract fun add(configurationName: String, dependencyNotation: Any): DependencyConstraint
Adds a dependency constraint to the given configuration.
abstract fun add(configurationName: String, dependencyNotation: Any, configureAction: Action<in DependencyConstraint>): DependencyConstraint
Adds a dependency constraint to the given configuration, and configures the dependency constraint using the given closure.
addProvider
Link copied to clipboard
abstract fun <T> addProvider(configurationName: String, dependencyNotation: Provider<T>)
Adds a dependency constraint provider to the given configuration.
abstract fun <T> addProvider(configurationName: String, dependencyNotation: Provider<T>, configureAction: Action<in DependencyConstraint>)
Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
addProviderConvertible
Link copied to clipboard
abstract fun <T> addProviderConvertible(configurationName: String, dependencyNotation: ProviderConvertible<T>)
Adds a dependency constraint provider to the given configuration.
abstract fun <T> addProviderConvertible(configurationName: String, dependencyNotation: ProviderConvertible<T>, configureAction: Action<in DependencyConstraint>)
Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
create
Link copied to clipboard
abstract fun create(dependencyConstraintNotation: Any): DependencyConstraint
Creates a dependency constraint without adding it to a configuration.
abstract fun create(dependencyConstraintNotation: Any, configureAction: Action<in DependencyConstraint>): DependencyConstraint
Creates a dependency constraint without adding it to a configuration, and configures the dependency constraint using the given closure.
enforcedPlatform
Link copied to clipboard
abstract fun enforcedPlatform(notation: Any): DependencyConstraint
abstract fun enforcedPlatform(notation: Any, configureAction: Action<in DependencyConstraint>): DependencyConstraint
Declares a constraint on an enforced platform.
invoke
Link copied to clipboard
operator fun DependencyConstraintHandler.invoke(configuration: DependencyConstraintHandlerScope.() -> Unit)

Configures the dependency constraints.