Avoid packaging two versions of same dependency in Gradle repackaging

Previously, the Gradle plugin would include all of the dependencies
from both the compile and runtime configurations in the repackaged
jar. In the unlikely event that the compile and runtime configurations
contained different versions of the same dependency, this would lead
to both versions of the dependency being packaged in the jar file.

The runtime configuration extends the compile configuration so, in
normal circumstances, it will contain a superset of the compile
configuration's dependencies. In the situation described above where
the two configurations contain different versions of the same
dependency the runtime configuration will only contain whichever
version of the two dependencies has "won". By default, this will
be the dependency with the higher version.

This commit updates the Gradle plugin to only include the runtime
configuration's resolved dependencies during repackaging. As explained
above, the runtime configuration extends the compile configuration so
any compile dependencies will still be included, with the added
benefit that duplicate versions of the same dependency will have been
resolved to a single, preferred version.

Closes gh-5749
This commit is contained in:
Andy Wilkinson
2016-04-21 11:37:40 +01:00
parent a6bcc6f573
commit 3bfc6b1a4b
3 changed files with 113 additions and 4 deletions

View File

@@ -87,16 +87,12 @@ class ProjectLibraries implements Libraries {
libraries(custom, callback);
}
else {
Set<GradleLibrary> compile = getLibraries("compile", LibraryScope.COMPILE);
Set<GradleLibrary> runtime = getLibraries("runtime", LibraryScope.RUNTIME);
runtime = minus(runtime, compile);
Set<GradleLibrary> provided = getLibraries(this.providedConfigurationName,
LibraryScope.PROVIDED);
if (provided != null) {
compile = minus(compile, provided);
runtime = minus(runtime, provided);
}
libraries(compile, callback);
libraries(runtime, callback);
libraries(provided, callback);
}