Skip to content

Instantly share code, notes, and snippets.

@slavashvets
Created March 13, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slavashvets/deed0ae9c8c38b17a4f8 to your computer and use it in GitHub Desktop.
Save slavashvets/deed0ae9c8c38b17a4f8 to your computer and use it in GitHub Desktop.
/**
Maven Resolution Strategy
=========================
Description:
Adds ability to set Maven-like conflict resolution strategy for any configuration
| Maven works on the principle of nearest wins strategy while resolving the dependency
| conflicts, that means whichever version it finds nearer in the tree, it will take
| that version and ignore the other versions.
| [http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/]
Usage:
1. Type `maven()` inside `resolutionStrategy` closure param
Example (apply to all configuration):
configurations.all.resolutionStrategy { maven() }
Example (apply to compile configuration):
configuration.compile.resolutionStrategy { maven() }
*/
project.configurations.all {
resolutionStrategy.extensions.add "maven", {
def versionMap = new HashMap()
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def moduleId = "${details.requested.group}:${details.requested.name}" as String
if (!versionMap.containsKey(moduleId)) {
versionMap[moduleId] = details.requested.version
} else {
details.useVersion versionMap[moduleId]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment