Package org.gradle.api.artifacts

## Interface DependencySubstitutions

-     public interface DependencySubstitutions

  Allows replacing dependencies with other dependencies.
  Since:
    2.5

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface | Description
    --- | --- | ---
    `static interface` | `DependencySubstitutions.Substitution` | Provides a DSL-friendly mechanism for specifying the target of a substitution.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DependencySubstitutions` | `all​(Action<? super DependencySubstitution> rule)` | Adds a dependency substitution rule that is triggered for every dependency (including transitive) when the configuration is being resolved.
    `ComponentSelector` | `module​(java.lang.String notation)` | Create a ModuleComponentSelector from the provided input string.
    `ComponentSelector` | `platform​(ComponentSelector selector)` | Transforms the provided selector into a platform selector.
    `ComponentSelector` | `project​(java.lang.String path)` | Create a ProjectComponentSelector from the provided input string.
    `DependencySubstitutions.Substitution` | `substitute​(ComponentSelector substitutedDependency)` | DSL-friendly mechanism to construct a dependency substitution for dependencies matching the provided selector.
    `ComponentSelector` | `variant​(ComponentSelector selector, Action<? super VariantSelectionDetails> detailsAction)` | Transforms the supplied selector into a specific variant selector.

- - ### Method Detail

    - #### all

          DependencySubstitutions all​(Action<? super DependencySubstitution> rule)

      Adds a dependency substitution rule that is triggered for every dependency (including transitive) when the configuration is being resolved. The action receives an instance of `DependencySubstitution` that can be used to find out what dependency is being resolved and to influence the resolution process.

      Example:

           configurations { main }
           // add dependency substitution rules
           configurations.main.resolutionStrategy.dependencySubstitution {
             // Use a rule to change the dependency module while leaving group + version intact
             all { DependencySubstitution dependency ->
               if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.module == 'groovy-all') {
                 dependency.useTarget dependency.requested.group + ':groovy:' + dependency.requested.version
               }
             }
             // Use a rule to replace all missing projects with module dependencies
             all { DependencySubstitution dependency ->
              if (dependency.requested instanceof ProjectComponentSelector) {
                 def targetProject = findProject(":${dependency.requested.path}")
                 if (targetProject == null) {
                   dependency.useTarget "org.myorg:" + dependency.requested.path + ":+"
                 }
               }
             }
           }

      The rules are evaluated in order they are declared. Rules are evaluated after forced modules are applied (see `ResolutionStrategy.force(Object...)`
      Returns:
        this

    - #### module

          ComponentSelector module​(java.lang.String notation)

      Create a ModuleComponentSelector from the provided input string. Strings must be in the format "{group}:{module}:{version}".

    - #### project

          ComponentSelector project​(java.lang.String path)

      Create a ProjectComponentSelector from the provided input string. Strings must be in the format ":path".

    - #### variant

          ComponentSelector variant​(ComponentSelector selector,
                                    Action<? super VariantSelectionDetails> detailsAction)

      Transforms the supplied selector into a specific variant selector.
      Parameters:
        `selector` - the origin selector
        `detailsAction` - the variant selection details configuration
      Since:
        6.6

    - #### platform

          ComponentSelector platform​(ComponentSelector selector)

      Transforms the provided selector into a platform selector.
      Parameters:
        `selector` - the original selector
      Since:
        6.6

    - #### substitute

          DependencySubstitutions.Substitution substitute​(ComponentSelector substitutedDependency)

      DSL-friendly mechanism to construct a dependency substitution for dependencies matching the provided selector.

      Examples:

           configurations { main }
           configurations.main.resolutionStrategy.dependencySubstitution {
             // Substitute project and module dependencies
             substitute module('org.gradle:api') using project(':api')
             substitute project(':util') using module('org.gradle:util:3.0')

             // Substitute one module dependency for another
             substitute module('org.gradle:api:2.0') using module('org.gradle:api:2.1')
           }