Created
March 13, 2016 16:53
-
-
Save slavashvets/deed0ae9c8c38b17a4f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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