public interface ResolutionStrategy
Examples:
plugins { id 'java' // so that there are some configurations } configurations.all { resolutionStrategy { // fail eagerly on version conflict (includes transitive dependencies) // e.g. multiple different versions of the same dependency (group and name are equal) failOnVersionConflict() // prefer modules that are part of this build (multi-project or composite build) over external modules preferProjectModules() // force certain versions of dependencies (including transitive) // *append new forced modules: force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4' // *replace existing forced modules with new ones: forcedModules = ['asm:asm-all:3.3.1'] // add dependency substitution rules dependencySubstitution { substitute module('org.gradle:api') using project(':api') substitute project(':util') using module('org.gradle:util:3.0') } // cache dynamic versions for 10 minutes cacheDynamicVersionsFor 10*60, 'seconds' // don't cache changing modules at all cacheChangingModulesFor 0, 'seconds' } }
Modifier and Type | Interface | Description |
---|---|---|
static class |
ResolutionStrategy.SortOrder |
Defines the sort order for components and artifacts produced by the configuration.
|
Modifier and Type | Method | Description |
---|---|---|
ResolutionStrategy |
activateDependencyLocking() |
Activates dependency locking support in Gradle.
|
void |
cacheChangingModulesFor(int value,
java.lang.String units) |
Sets the length of time that changing modules will be cached, with units expressed as a String.
|
void |
cacheChangingModulesFor(int value,
java.util.concurrent.TimeUnit units) |
Sets the length of time that changing modules will be cached.
|
void |
cacheDynamicVersionsFor(int value,
java.lang.String units) |
Sets the length of time that dynamic versions will be cached, with units expressed as a String.
|
void |
cacheDynamicVersionsFor(int value,
java.util.concurrent.TimeUnit units) |
Sets the length of time that dynamic versions will be cached.
|
ResolutionStrategy |
capabilitiesResolution(Action<? super CapabilitiesResolution> action) |
Configures the capabilities resolution strategy.
|
ResolutionStrategy |
componentSelection(Action<? super ComponentSelectionRules> action) |
The componentSelection block provides rules to filter or prevent certain components from appearing in the resolution result.
|
ResolutionStrategy |
deactivateDependencyLocking() |
Deactivates dependency locking support in Gradle.
|
ResolutionStrategy |
dependencySubstitution(Action<? super DependencySubstitutions> action) |
Configures the set of dependency substitution rules for this configuration.
|
ResolutionStrategy |
disableDependencyVerification() |
Deactivates dependency verification for this configuration.
|
ResolutionStrategy |
eachDependency(Action<? super DependencyResolveDetails> rule) |
Adds a dependency substitution rule that is triggered for every dependency (including transitive)
when the configuration is being resolved.
|
ResolutionStrategy |
enableDependencyVerification() |
Enabled dependency verification for this configuration.
|
ResolutionStrategy |
failOnChangingVersions() |
If this method is called, Gradle will make sure that no changing version participates in resolution.
|
ResolutionStrategy |
failOnDynamicVersions() |
If this method is called, Gradle will make sure that no dynamic version was used in the resulting dependency graph.
|
ResolutionStrategy |
failOnNonReproducibleResolution() |
Configures Gradle to fail the build is the resolution result is expected to be unstable, that is to say that
it includes dynamic versions or changing versions and therefore the result may change depending
on when the build is executed.
|
ResolutionStrategy |
failOnVersionConflict() |
In case of conflict, Gradle by default uses the newest of conflicting versions.
|
ResolutionStrategy |
force(java.lang.Object... moduleVersionSelectorNotations) |
Allows forcing certain versions of dependencies, including transitive dependencies.
|
CapabilitiesResolution |
getCapabilitiesResolution() |
Returns the capabilities resolution strategy.
|
ComponentSelectionRules |
getComponentSelection() |
Returns the currently configured version selection rules object.
|
DependencySubstitutions |
getDependencySubstitution() |
Returns the set of dependency substitution rules that are set for this configuration.
|
java.util.Set<ModuleVersionSelector> |
getForcedModules() |
Returns currently configured forced modules.
|
Property<java.lang.Boolean> |
getUseGlobalDependencySubstitutionRules() |
Gradle implicitly registers dependency substitution rules for all configurations in the whole build
tree to find projects in other included builds.
|
void |
preferProjectModules() |
Gradle can resolve conflicts purely by version number or prioritize project dependencies over binary.
|
ResolutionStrategy |
setForcedModules(java.lang.Object... moduleVersionSelectorNotations) |
Allows forcing certain versions of dependencies, including transitive dependencies.
|
void |
sortArtifacts(ResolutionStrategy.SortOrder sortOrder) |
Specifies the ordering for resolved artifacts.
|
ResolutionStrategy failOnVersionConflict()
Configuration
.
The check includes both first level and transitive dependencies. See example below:
plugins { id 'java' // so that there are some configurations } configurations.all { resolutionStrategy.failOnVersionConflict() }
ResolutionStrategy failOnDynamicVersions()
ResolutionStrategy failOnChangingVersions()
ResolutionStrategy failOnNonReproducibleResolution()
failOnDynamicVersions()
and
failOnChangingVersions()
.void preferProjectModules()
This applies to both first level and transitive dependencies. See example below:
plugins { id 'java' // so that there are some configurations } configurations.all { resolutionStrategy.preferProjectModules() }
ResolutionStrategy activateDependencyLocking()
ResolutionStrategy deactivateDependencyLocking()
ResolutionStrategy disableDependencyVerification()
ResolutionStrategy enableDependencyVerification()
ResolutionStrategy force(java.lang.Object... moduleVersionSelectorNotations)
It accepts following notations:
ModuleVersionSelector
plugins { id 'java' // so that there are some configurations } configurations.all { resolutionStrategy.force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4' }
moduleVersionSelectorNotations
- typically group:name:version notations to appendResolutionStrategy setForcedModules(java.lang.Object... moduleVersionSelectorNotations)
For information on notations see force(Object...)
Example:
plugins { id 'java' // so that there are some configurations } configurations.all { resolutionStrategy.forcedModules = ['asm:asm-all:3.3.1', 'commons-io:commons-io:1.4'] }
moduleVersionSelectorNotations
- typically group:name:version notations to setjava.util.Set<ModuleVersionSelector> getForcedModules()
force(Object...)
ResolutionStrategy eachDependency(Action<? super DependencyResolveDetails> rule)
DependencyResolveDetails
that can be used to find out what dependency is being resolved and to influence the resolution process.
Example:
configurations { compileClasspath.resolutionStrategy { eachDependency { DependencyResolveDetails details -> //specifying a fixed version for all libraries with 'org.gradle' group if (details.requested.group == 'org.gradle') { details.useVersion '1.4' } } eachDependency { details -> //multiple actions can be specified if (details.requested.name == 'groovy-all') { //changing the name: details.useTarget group: details.requested.group, name: 'groovy', version: details.requested.version } } } }The rules are evaluated in order they are declared. Rules are evaluated after forced modules are applied (see
force(Object...)
void cacheDynamicVersionsFor(int value, java.lang.String units)
A convenience method for cacheDynamicVersionsFor(int, java.util.concurrent.TimeUnit)
with units expressed as a String.
Units are resolved by calling the valueOf(String)
method of TimeUnit
with the upper-cased string value.
value
- The number of time unitsunits
- The unitsvoid cacheDynamicVersionsFor(int value, java.util.concurrent.TimeUnit units)
Gradle keeps a cache of dynamic version => resolved version (ie 2.+ => 2.3). By default, these cached values are kept for 24 hours, after which the cached entry is expired and the dynamic version is resolved again.
Use this method to provide a custom expiry time after which the cached value for any dynamic version will be expired.
value
- The number of time unitsunits
- The unitsvoid cacheChangingModulesFor(int value, java.lang.String units)
A convenience method for cacheChangingModulesFor(int, java.util.concurrent.TimeUnit)
with units expressed as a String.
Units are resolved by calling the valueOf(String)
method of TimeUnit
with the upper-cased string value.
value
- The number of time unitsunits
- The unitsvoid cacheChangingModulesFor(int value, java.util.concurrent.TimeUnit units)
Gradle caches the contents and artifacts of changing modules. By default, these cached values are kept for 24 hours, after which the cached entry is expired and the module is resolved again.
Use this method to provide a custom expiry time after which the cached entries for any changing module will be expired.
value
- The number of time unitsunits
- The unitsComponentSelectionRules getComponentSelection()
ResolutionStrategy componentSelection(Action<? super ComponentSelectionRules> action)
action
- Action to be applied to the ComponentSelectionRules
DependencySubstitutions getDependencySubstitution()
ResolutionStrategy dependencySubstitution(Action<? super DependencySubstitutions> action)
DependencySubstitutions
which
can then be configured with substitution rules.
Examples:
// add dependency substitution rules configurations.all { 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') } }
DependencySubstitutions
Property<java.lang.Boolean> getUseGlobalDependencySubstitutionRules()
void sortArtifacts(ResolutionStrategy.SortOrder sortOrder)
ResolutionStrategy.SortOrder.DEFAULT
: Don't specify the sort order. Gradle will provide artifacts in the default order.ResolutionStrategy.SortOrder.CONSUMER_FIRST
: Artifacts for a consuming component should appear before artifacts for its dependencies.ResolutionStrategy.SortOrder.DEPENDENCY_FIRST
: Artifacts for a consuming component should appear after artifacts for its dependencies.ResolutionStrategy.SortOrder
, but no guarantees will be made in the presence of dependency cycles.
NOTE: For a particular Gradle version, artifact ordering will be consistent. Multiple resolves for the same inputs will result in the
same outputs in the same order.ResolutionStrategy capabilitiesResolution(Action<? super CapabilitiesResolution> action)
action
- the configuration action.CapabilitiesResolution getCapabilitiesResolution()