# Class DependencyModifier

java.lang.Object
org.gradle.api.artifacts.dsl.DependencyModifier

Direct Known Subclasses:
  `PlatformDependencyModifiers.EnforcedPlatformDependencyModifier, PlatformDependencyModifiers.PlatformDependencyModifier, TestFixturesDependencyModifiers.TestFixturesDependencyModifier`

@NonExtensible public abstract class DependencyModifier extends Object
A `DependencyModifier` defines how to modify a dependency inside a custom `dependencies` block to select a different variant.

Since:
  8.0
API Note:
  Gradle has specific extensions to make explicit calls to `modify(...)` unnecessary from the DSL.
  - For Groovy DSL, we create `call(...)` equivalents for all the `modify(...)` methods.
  - For Kotlin DSL, we create `invoke(...)` equivalents for all the `modify(...)` methods.
Implementation Requirements:
  The only method that should be implemented is `modifyImplementation(ModuleDependency)`. Other `abstract` methods are used to inject necessary services and should not be implemented.
Implementation Note:
  All implementations of `modify(...)` delegate to `modifyImplementation(ModuleDependency)`.

  Changes to this interface may require changes to the `extension module for Groovy DSL` or `extension functions for Kotlin DSL`.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `DependencyModifier()`
  Creates a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected abstract DependencyFactory`
  `getDependencyFactory()`
  A dependency factory is used to convert supported dependency notations into `Dependency` instances.
  `final <D extends ModuleDependency>
  D`
  `modify(D dependency)`
  Takes a given `ModuleDependency` and modifies the dependency to select the variant of the given module.
  `final ExternalModuleDependency`
  `modify(CharSequence dependencyNotation)`
  Create an `ExternalModuleDependency` from the given notation and modifies it to select the variant of the given module as described in `modify(ModuleDependency)`.
  `final <D extends ModuleDependency>
  Provider<D>`
  `modify(Provider<D> providerToDependency)`
  Takes a given `Provider` to a `ExternalModuleDependency` and modifies the dependency to select the variant of the given module as described in `modify(ModuleDependency)`.
  `final Provider<? extends MinimalExternalModuleDependency>`
  `modify(ProviderConvertible<? extends MinimalExternalModuleDependency> providerConvertibleToDependency)`
  Takes a given `Provider` to a `MinimalExternalModuleDependency` and modifies the dependency to select the variant of the given module as described in `modify(ModuleDependency)`.
  `protected abstract void`
  `modifyImplementation(ModuleDependency dependency)`
  Modify the given dependency.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DependencyModifier

    protected DependencyModifier()
    Creates a new instance.
    Since:
      8.4

- ## Method Details

  - ### getDependencyFactory

    @Inject protected abstract DependencyFactory getDependencyFactory()
    A dependency factory is used to convert supported dependency notations into `Dependency` instances.
    Returns:
      a dependency factory
    See Also:
      - `DependencyFactory`
    Implementation Requirements:
      Do not implement this method. Gradle generates the implementation automatically.

  - ### modify

    public final ExternalModuleDependency modify(CharSequence dependencyNotation)
    Create an `ExternalModuleDependency` from the given notation and modifies it to select the variant of the given module as described in `modify(ModuleDependency)`.
    Parameters:
      `dependencyNotation` - the dependency notation
    Returns:
      the modified dependency
    Since:
      8.0
    See Also:
      - `DependencyFactory.create(CharSequence)`

  - ### modify

    @Incubating public final Provider<? extends MinimalExternalModuleDependency> modify(ProviderConvertible<? extends MinimalExternalModuleDependency> providerConvertibleToDependency)
    Takes a given `Provider` to a `MinimalExternalModuleDependency` and modifies the dependency to select the variant of the given module as described in `modify(ModuleDependency)`.
    Parameters:
      `providerConvertibleToDependency` - the provider
    Returns:
      a provider to the modified dependency
    Since:
      8.0

  - ### modify

    public final <D extends ModuleDependency> Provider<D> modify(Provider<D> providerToDependency)
    Takes a given `Provider` to a `ExternalModuleDependency` and modifies the dependency to select the variant of the given module as described in `modify(ModuleDependency)`.
    Parameters:
      `providerToDependency` - the provider
    Returns:
      a provider to the modified dependency
    Since:
      8.0

  - ### modify

    public final <D extends ModuleDependency> D modify(D dependency)
    Takes a given `ModuleDependency` and modifies the dependency to select the variant of the given module. Dependency resolution may fail if the given module does not have a compatible variant.

    The dependency will be copied, so the original dependency will not be modified.

    Type Parameters:
      `D` - the type of the `ModuleDependency`
    Parameters:
      `dependency` - the dependency to modify
    Returns:
      the modified dependency
    Since:
      8.0

  - ### modifyImplementation

    protected abstract void modifyImplementation(ModuleDependency dependency)
    Modify the given dependency.
    Parameters:
      `dependency` - the dependency to modify
    Since:
      8.4
    Implementation Requirements:
      This method must be implemented.