Resolve versionManagement configuration lazily and preserve exclusions

Previously, the versionManagement configuration was resolved as part of
the Boot Gradle plugin being applied. This meant that no dependencies
could be added to it and attempting to do so would result in a failure:
“You can't change a configuration which is not in unresolved state”.
This commit updates ApplyExcludeRules to wrap its processing in a
before resolve action. This defers the resolution of the
versionManagement configuration until one of the project’s other
configurations is being resolved. Fixes #1077

In addition to the above, the transitive exclusions that the Gradle
plugin provides were being lost if custom version management provided
a version for the same dependency. This commit updates
AbstractDependencies to preserve the exclusions from an existing
dependency declaration while using the version from the newer
dependency. This ensures that the exclusions remain while allowing
versions to be overridden. Fixes #1079
This commit is contained in:
Andy Wilkinson
2014-06-11 15:50:18 +01:00
parent 9e93719922
commit f5f3903538
8 changed files with 201 additions and 20 deletions

View File

@@ -16,14 +16,19 @@
package org.springframework.boot.dependency.tools;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.boot.dependency.tools.Dependency.Exclusion;
/**
* Abstract base implementation for {@link Dependencies}.
*
*
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.1.0
*/
abstract class AbstractDependencies implements Dependencies {
@@ -53,10 +58,24 @@ abstract class AbstractDependencies implements Dependencies {
}
protected void add(ArtifactAndGroupId artifactAndGroupId, Dependency dependency) {
Dependency existing = this.byArtifactAndGroupId.get(artifactAndGroupId);
if (existing != null) {
dependency = mergeDependencies(existing, dependency);
}
this.byArtifactAndGroupId.put(artifactAndGroupId, dependency);
this.byArtifactId.put(dependency.getArtifactId(), dependency);
}
private Dependency mergeDependencies(Dependency existingDependency,
Dependency newDependency) {
List<Exclusion> combinedExclusions = new ArrayList<Exclusion>();
combinedExclusions.addAll(existingDependency.getExclusions());
combinedExclusions.addAll(newDependency.getExclusions());
return new Dependency(newDependency.getGroupId(), newDependency.getArtifactId(),
newDependency.getVersion(), combinedExclusions);
}
/**
* Simple holder for an artifact+group ID.
*/