DependencyConstraintHandler - Gradle DSL Version 9.3.1

# DependencyConstraintHandler

API Documentation: | `DependencyConstraintHandler`

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 `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")
        }
    }

#### Project dependencies

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

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

### Properties

No properties

### Methods

Method | Description
`add(configurationName, dependencyNotation)` | Adds a dependency constraint to the given configuration.
`add(configurationName, dependencyNotation, configureAction)` | Adds a dependency constraint to the given configuration, and configures the dependency constraint using the given closure.
`create(dependencyConstraintNotation)` | Creates a dependency constraint without adding it to a configuration.
`create(dependencyConstraintNotation, configureAction)` | Creates a dependency constraint without adding it to a configuration, and configures the dependency constraint using the given closure.
`enforcedPlatform(notation)` | Declares a constraint on an enforced platform. If the target coordinates represent multiple potential components, the platform component will be selected, instead of the library. An enforced platform is a platform for which the direct dependencies are forced, meaning that they would override any other version found in the graph.
`enforcedPlatform(notation, configureAction)` | Declares a constraint on an enforced platform. If the target coordinates represent multiple potential components, the platform component will be selected, instead of the library. An enforced platform is a platform for which the direct dependencies are forced, meaning that they would override any other version found in the graph.

### Script blocks

No script blocks

### Method details

#### `DependencyConstraint` `add`(`String` configurationName, `Object` dependencyNotation)

Adds a dependency constraint to the given configuration.

#### `DependencyConstraint` `add`(`String` configurationName, `Object` dependencyNotation, ``Action`<? super `DependencyConstraint`>` configureAction)

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

#### `DependencyConstraint` `create`(`Object` dependencyConstraintNotation)

Creates a dependency constraint without adding it to a configuration.

#### `DependencyConstraint` `create`(`Object` dependencyConstraintNotation, ``Action`<? super `DependencyConstraint`>` configureAction)

Creates a dependency constraint without adding it to a configuration, and configures the dependency constraint using the given closure.

#### `DependencyConstraint` `enforcedPlatform`(`Object` notation)

Declares a constraint on an enforced platform. If the target coordinates represent multiple potential components, the platform component will be selected, instead of the library. An enforced platform is a platform for which the direct dependencies are forced, meaning that they would override any other version found in the graph.

#### `DependencyConstraint` `enforcedPlatform`(`Object` notation, ``Action`<? super `DependencyConstraint`>` configureAction)

Declares a constraint on an enforced platform. If the target coordinates represent multiple potential components, the platform component will be selected, instead of the library. An enforced platform is a platform for which the direct dependencies are forced, meaning that they would override any other version found in the graph.