DependencyConstraintHandler (Gradle API 8.14.5)
Description: declaration: package: org.gradle.api.artifacts.dsl, interface: DependencyConstraintHandler

Package org.gradle.api.artifacts.dsl

# Interface DependencyConstraintHandler

@ServiceScope(org.gradle.internal.service.scopes.Scope.Project.class) public interface 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

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `<T> void`
  `addProvider(String configurationName, Provider<T> dependencyNotation)`
  Adds a dependency constraint provider to the given configuration.
  `<T> void`
  `addProvider(String configurationName, Provider<T> dependencyNotation, Action<? super DependencyConstraint> configureAction)`
  Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
  `<T> void`
  `addProviderConvertible(String configurationName, ProviderConvertible<T> dependencyNotation)`
  Adds a dependency constraint provider to the given configuration.
  `<T> void`
  `addProviderConvertible(String configurationName, ProviderConvertible<T> dependencyNotation, Action<? super DependencyConstraint> configureAction)`
  Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
  `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.
  `DependencyConstraint`
  `enforcedPlatform(Object notation, Action<? super DependencyConstraint> configureAction)`
  Declares a constraint on an enforced platform.

- ## Method Details

  - ### add

    DependencyConstraint add(String configurationName, Object dependencyNotation)
    Adds a dependency constraint to the given configuration.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation

  - ### add

    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.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation
      `configureAction` - The closure to use to configure the dependency constraint.

  - ### addProvider

    <T> void addProvider(String configurationName, Provider<T> dependencyNotation)
    Adds a dependency constraint provider to the given configuration.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation provider, in one of the notations described above.
    Since:
      8.12

  - ### addProvider

    <T> void addProvider(String configurationName, Provider<T> dependencyNotation, Action<? super DependencyConstraint> configureAction)
    Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation provider, in one of the notations described above.
      `configureAction` - The action to use to configure the dependency constraint.
    Since:
      8.12

  - ### addProviderConvertible

    <T> void addProviderConvertible(String configurationName, ProviderConvertible<T> dependencyNotation)
    Adds a dependency constraint provider to the given configuration.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation provider, in one of the notations described above.
    Since:
      8.12

  - ### addProviderConvertible

    <T> void addProviderConvertible(String configurationName, ProviderConvertible<T> dependencyNotation, Action<? super DependencyConstraint> configureAction)
    Adds a dependency constraint provider to the given configuration, eventually configures the dependency constraint using the given action.
    Parameters:
      `configurationName` - The name of the configuration.
      `dependencyNotation` - The dependency constraint notation provider, in one of the notations described above.
      `configureAction` - The action to use to configure the dependency constraint.
    Since:
      8.12

  - ### create

    DependencyConstraint create(Object dependencyConstraintNotation)
    Creates a dependency constraint without adding it to a configuration.
    Parameters:
      `dependencyConstraintNotation` - The dependency constraint notation.

  - ### create

    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.
    Parameters:
      `dependencyConstraintNotation` - The dependency constraint notation.
      `configureAction` - The closure to use to configure the dependency.

  - ### enforcedPlatform

    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.
    Parameters:
      `notation` - the coordinates of the platform
    Since:
      5.0

  - ### enforcedPlatform

    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.
    Parameters:
      `notation` - the coordinates of the platform
      `configureAction` - the dependency configuration block
    Since:
      5.0