diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java index fe1f0beb74..4b004be99a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java @@ -44,18 +44,17 @@ public class DependencyResolutionContext { private final List managedDependencies = new ArrayList(); - private DependencyManagement dependencyManagement = new SpringBootDependenciesDependencyManagement(); + private DependencyManagement dependencyManagement = null; - private ArtifactCoordinatesResolver artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver( - this.dependencyManagement); + private ArtifactCoordinatesResolver artifactCoordinatesResolver; public DependencyResolutionContext() { - addDependencyManagement(this.dependencyManagement); + addDependencyManagement(new SpringBootDependenciesDependencyManagement()); } private String getIdentifier(Dependency dependency) { - return getIdentifier(dependency.getArtifact().getGroupId(), dependency - .getArtifact().getArtifactId()); + return getIdentifier(dependency.getArtifact().getGroupId(), + dependency.getArtifact().getArtifactId()); } private String getIdentifier(String groupId, String artifactId) { @@ -69,8 +68,8 @@ public class DependencyResolutionContext { public String getManagedVersion(String groupId, String artifactId) { Dependency dependency = getManagedDependency(groupId, artifactId); if (dependency == null) { - dependency = this.managedDependencyByGroupAndArtifact.get(getIdentifier( - groupId, artifactId)); + dependency = this.managedDependencyByGroupAndArtifact + .get(getIdentifier(groupId, artifactId)); } return dependency != null ? dependency.getArtifact().getVersion() : null; } @@ -98,19 +97,23 @@ public class DependencyResolutionContext { List aetherExclusions = new ArrayList(); for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency .getExclusions()) { - aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion - .getArtifactId(), "*", "*")); + aetherExclusions.add(new Exclusion(exclusion.getGroupId(), + exclusion.getArtifactId(), "*", "*")); } - Dependency aetherDependency = new Dependency(new DefaultArtifact( - dependency.getGroupId(), dependency.getArtifactId(), "jar", - dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions); + Dependency aetherDependency = new Dependency( + new DefaultArtifact(dependency.getGroupId(), + dependency.getArtifactId(), "jar", dependency.getVersion()), + JavaScopes.COMPILE, false, aetherExclusions); this.managedDependencies.add(0, aetherDependency); this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), aetherDependency); } + this.dependencyManagement = this.dependencyManagement == null + ? dependencyManagement + : new CompositeDependencyManagement(dependencyManagement, + this.dependencyManagement); this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver( - new CompositeDependencyManagement(dependencyManagement, - this.dependencyManagement)); + this.dependencyManagement); } }