withDependencies

Execute the given action before the configuration first participates in dependency resolution. Actions will be executed in the order provided. A configuration will participate in dependency resolution when:

In general, this method should be avoided in favor of other lazy APIs. However, in some cases where lazy APIs are not yet available, this method can be used to perform actions before the configuration is used.

Despite the method's name, callbacks registered on this method should not add dependencies to the configuration or mutate the dependencies already present on the configuration. Instead, use the Provider-accepting methods on DependencySet and DependencyConstraintSet.

Consider the following example that lazily adds a dependency to a configuration:

configurations { conf }
configurations['conf'].dependencies.addLater(provider {
    project.dependencies.create("com:example:1.0")
})
Similarly, instead of mutating an existing dependency, use dependency constraints instead. Consider the following example that uses a dependency constraint to prefer a specific version of a dependency if the dependency has not declared a preferred version itself. If the dependency has declared a version, the preferred version constraint will be ignored:
configurations { conf }
dependencies {
    conf("com:example")

    constraints {
        conf("com:example") {
            version {
                prefer("2.0")
            }
        }
    }
}
In some cases, using this method may still be necessary:
  • Adding excludes: This method may be used to lazily add excludes to a Configuration. Adding excludes to declared dependencies should be handled with component metadata rules
  • Mutating configuration hierarchy: Mutating a configuration's hierarchy (extendsFrom) after declaration is highly discouraged. However, doing so is possible with this method.

Since

4.4

Return

this

Parameters

action

a dependency action to execute before the configuration is used.