Browse Source
This commit replaces Spring Boot's basic dependency management support with separate dependency management plugin. This has a number of benefits including: 1. A Maven bom can be used rather than a custom properties file 2. Dependency management is applied transitively rather than only to direct dependencies 3. Exclusions are applied as they would be in Maven 4. Gradle-generated poms are automatically configured with the appropriate dependency management Closes gh-2133pull/2695/head
59 changed files with 132 additions and 1090 deletions
@ -1,55 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import org.gradle.tooling.ProjectConnection; |
|
||||||
import org.junit.BeforeClass; |
|
||||||
import org.junit.Test; |
|
||||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
|
||||||
|
|
||||||
/** |
|
||||||
* Tests for using the Gradle plugin's support for custom version management |
|
||||||
* |
|
||||||
* @author Andy Wilkinson |
|
||||||
*/ |
|
||||||
public class CustomVersionManagementTests { |
|
||||||
|
|
||||||
private static final String BOOT_VERSION = ManagedDependencies.get() |
|
||||||
.find("spring-boot").getVersion(); |
|
||||||
|
|
||||||
private static ProjectConnection project; |
|
||||||
|
|
||||||
@BeforeClass |
|
||||||
public static void createProject() throws IOException { |
|
||||||
project = new ProjectCreator().createProject("custom-version-management"); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void exclusionsAreStillInPlace() { |
|
||||||
project.newBuild().forTasks("checkExclusions") |
|
||||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run(); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void customSpringVersionIsUsed() { |
|
||||||
project.newBuild().forTasks("checkSpringVersion") |
|
||||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,63 +0,0 @@ |
|||||||
import org.gradle.api.artifacts.result.UnresolvedDependencyResult; |
|
||||||
|
|
||||||
buildscript { |
|
||||||
repositories { |
|
||||||
mavenLocal() |
|
||||||
mavenCentral() |
|
||||||
} |
|
||||||
dependencies { |
|
||||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}") |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
repositories { |
|
||||||
mavenLocal() |
|
||||||
mavenCentral() |
|
||||||
} |
|
||||||
|
|
||||||
configurations { |
|
||||||
exclusions |
|
||||||
springVersion |
|
||||||
} |
|
||||||
|
|
||||||
apply plugin: 'spring-boot' |
|
||||||
|
|
||||||
dependencies { |
|
||||||
exclusions "org.springframework.boot:spring-boot-starter" |
|
||||||
springVersion "org.springframework:spring-core" |
|
||||||
versionManagement files('../../src/test/resources/custom-versions.properties') |
|
||||||
} |
|
||||||
|
|
||||||
task checkExclusions { |
|
||||||
doFirst { |
|
||||||
def commonsLogging = getResolvedDependencies(configurations.exclusions) |
|
||||||
.find { it.selected.id.group == 'commons-logging' } |
|
||||||
if (commonsLogging) { |
|
||||||
throw new GradleException("commong-logging is a transitive dependency") |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
task checkSpringVersion { |
|
||||||
doFirst { |
|
||||||
def springVersions = getResolvedDependencies(configurations.springVersion) |
|
||||||
.findAll{it.selected.id.group == 'org.springframework'} |
|
||||||
.collect {it.selected.id.version} |
|
||||||
if (springVersions.size() != 1 || !springVersions.contains("4.0.3.RELEASE")) { |
|
||||||
throw new GradleException("Spring version was not 4.0.3.RELEASE") |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
def getResolvedDependencies(def configuration) { |
|
||||||
def allDependencies = configuration.incoming |
|
||||||
.resolutionResult.allDependencies |
|
||||||
.split { it instanceof UnresolvedDependencyResult } |
|
||||||
|
|
||||||
def unresolved = allDependencies.first() |
|
||||||
def resolved = allDependencies.last() |
|
||||||
if (unresolved) { |
|
||||||
throw new GradleException("Resolution failed: ${unresolved}") |
|
||||||
} |
|
||||||
resolved |
|
||||||
} |
|
||||||
@ -1,2 +0,0 @@ |
|||||||
org.springframework\:spring-core=4.0.3.RELEASE |
|
||||||
org.springframework.boot\:spring-boot-starter=1.1.0.RELEASE |
|
||||||
@ -1,41 +0,0 @@ |
|||||||
buildscript { |
|
||||||
repositories { |
|
||||||
mavenLocal() |
|
||||||
} |
|
||||||
dependencies { |
|
||||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}") |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
apply plugin: 'java' |
|
||||||
apply plugin: 'maven' |
|
||||||
apply plugin: 'spring-boot' |
|
||||||
|
|
||||||
group = 'installer' |
|
||||||
version = '0.0.0' |
|
||||||
|
|
||||||
install { |
|
||||||
repositories.mavenInstaller { |
|
||||||
pom.project { |
|
||||||
parent { |
|
||||||
groupId 'org.springframework.boot' |
|
||||||
artifactId 'spring-boot-starter-parent' |
|
||||||
version "${project.bootVersion}" |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
jar { |
|
||||||
baseName = 'installer' |
|
||||||
} |
|
||||||
|
|
||||||
repositories { |
|
||||||
mavenLocal() |
|
||||||
mavenCentral() |
|
||||||
} |
|
||||||
|
|
||||||
dependencies { |
|
||||||
versionManagement 'io.spring.platform:platform-versions:1.0.0.RELEASE@properties' |
|
||||||
compile "org.springframework.boot:spring-boot-starter" |
|
||||||
} |
|
||||||
@ -1,86 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.FileInputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.Collection; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Set; |
|
||||||
|
|
||||||
import org.gradle.api.Project; |
|
||||||
import org.gradle.api.artifacts.Configuration; |
|
||||||
import org.springframework.boot.dependency.tools.Dependencies; |
|
||||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
|
||||||
import org.springframework.boot.dependency.tools.PropertiesFileDependencies; |
|
||||||
|
|
||||||
/** |
|
||||||
* Utility to provide access to {@link ManagedDependencies} with support for version file |
|
||||||
* overrides. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
public class VersionManagedDependencies { |
|
||||||
|
|
||||||
public static final String CONFIGURATION = "versionManagement"; |
|
||||||
|
|
||||||
private Configuration versionManagementConfiguration; |
|
||||||
|
|
||||||
private Collection<Dependencies> versionManagedDependencies; |
|
||||||
|
|
||||||
private ManagedDependencies managedDependencies; |
|
||||||
|
|
||||||
public VersionManagedDependencies(Project project) { |
|
||||||
this.versionManagementConfiguration = project.getConfigurations().getByName( |
|
||||||
CONFIGURATION); |
|
||||||
} |
|
||||||
|
|
||||||
public ManagedDependencies getManagedDependencies() { |
|
||||||
if (this.managedDependencies == null) { |
|
||||||
this.managedDependencies = ManagedDependencies |
|
||||||
.get(getVersionManagedDependencies()); |
|
||||||
} |
|
||||||
return this.managedDependencies; |
|
||||||
} |
|
||||||
|
|
||||||
private Collection<Dependencies> getVersionManagedDependencies() { |
|
||||||
if (versionManagedDependencies == null) { |
|
||||||
Set<File> files = versionManagementConfiguration.resolve(); |
|
||||||
List<Dependencies> dependencies = new ArrayList<Dependencies>(files.size()); |
|
||||||
for (File file : files) { |
|
||||||
dependencies.add(getPropertiesFileManagedDependencies(file)); |
|
||||||
} |
|
||||||
this.versionManagedDependencies = dependencies; |
|
||||||
} |
|
||||||
return versionManagedDependencies; |
|
||||||
} |
|
||||||
|
|
||||||
private Dependencies getPropertiesFileManagedDependencies(File file) { |
|
||||||
if (!file.getName().toLowerCase().endsWith(".properties")) { |
|
||||||
throw new IllegalStateException(file + " is not a version property file"); |
|
||||||
} |
|
||||||
try { |
|
||||||
return new PropertiesFileDependencies(new FileInputStream(file)); |
|
||||||
} |
|
||||||
catch (IOException ex) { |
|
||||||
throw new IllegalStateException(ex); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2015 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.boot.gradle.dependencymanagement; |
||||||
|
|
||||||
|
import io.spring.gradle.dependencymanagement.DependencyManagementExtension |
||||||
|
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin |
||||||
|
|
||||||
|
import org.gradle.api.Project |
||||||
|
import org.springframework.boot.gradle.PluginFeatures |
||||||
|
|
||||||
|
/** |
||||||
|
* {@link PluginFeatures} to configure dependency management |
||||||
|
* |
||||||
|
* @author Andy Wilkinson |
||||||
|
*/ |
||||||
|
class DependencyManagementPluginFeatures implements PluginFeatures { |
||||||
|
|
||||||
|
@Override |
||||||
|
void apply(Project project) { |
||||||
|
project.plugins.apply(DependencyManagementPlugin) |
||||||
|
DependencyManagementExtension dependencyManagement = project.extensions |
||||||
|
.findByType(DependencyManagementExtension) |
||||||
|
dependencyManagement.imports { |
||||||
|
def version = DependencyManagementPluginFeatures.class.getPackage().implementationVersion |
||||||
|
mavenBom "org.springframework.boot:spring-boot-starter-parent:$version" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,115 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle.exclude; |
|
||||||
|
|
||||||
import org.gradle.api.Action; |
|
||||||
import org.gradle.api.Project; |
|
||||||
import org.gradle.api.artifacts.Configuration; |
|
||||||
import org.gradle.api.artifacts.Dependency; |
|
||||||
import org.gradle.api.artifacts.ModuleDependency; |
|
||||||
import org.gradle.api.artifacts.ResolvableDependencies; |
|
||||||
import org.gradle.api.internal.artifacts.DefaultExcludeRule; |
|
||||||
import org.gradle.api.logging.Logger; |
|
||||||
import org.springframework.boot.dependency.tools.Dependency.Exclusion; |
|
||||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
|
||||||
import org.springframework.boot.gradle.VersionManagedDependencies; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Action} to apply exclude rules. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
public class ApplyExcludeRules implements Action<Configuration> { |
|
||||||
|
|
||||||
private final Logger logger; |
|
||||||
|
|
||||||
private final VersionManagedDependencies versionManagedDependencies; |
|
||||||
|
|
||||||
public ApplyExcludeRules(Project project) { |
|
||||||
this.logger = project.getLogger(); |
|
||||||
this.versionManagedDependencies = new VersionManagedDependencies(project); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void execute(Configuration configuration) { |
|
||||||
if (!VersionManagedDependencies.CONFIGURATION.equals(configuration.getName())) { |
|
||||||
configuration.getIncoming().beforeResolve( |
|
||||||
new Action<ResolvableDependencies>() { |
|
||||||
@Override |
|
||||||
public void execute(ResolvableDependencies resolvableDependencies) { |
|
||||||
resolvableDependencies.getDependencies().all( |
|
||||||
new Action<Dependency>() { |
|
||||||
@Override |
|
||||||
public void execute(Dependency dependency) { |
|
||||||
applyExcludeRules(dependency); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void applyExcludeRules(Dependency dependency) { |
|
||||||
if (dependency instanceof ModuleDependency) { |
|
||||||
applyExcludeRules((ModuleDependency) dependency); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void applyExcludeRules(ModuleDependency dependency) { |
|
||||||
ManagedDependencies managedDependencies = versionManagedDependencies |
|
||||||
.getManagedDependencies(); |
|
||||||
// flat directory repositories do not have groups
|
|
||||||
if (dependency.getGroup() != null) { |
|
||||||
org.springframework.boot.dependency.tools.Dependency managedDependency = managedDependencies |
|
||||||
.find(dependency.getGroup(), dependency.getName()); |
|
||||||
if (managedDependency != null) { |
|
||||||
for (Exclusion exclusion : managedDependency.getExclusions()) { |
|
||||||
addExcludeRule(dependency, exclusion); |
|
||||||
} |
|
||||||
addImplicitExcludeRules(dependency); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
logger.debug("No exclusions rules applied for non-managed dependency " |
|
||||||
+ dependency); |
|
||||||
} |
|
||||||
|
|
||||||
private void addExcludeRule(ModuleDependency dependency, Exclusion exclusion) { |
|
||||||
logger.info("Adding managed exclusion rule " + exclusion + " to " + dependency); |
|
||||||
DefaultExcludeRule rule = new DefaultExcludeRule(exclusion.getGroupId(), |
|
||||||
exclusion.getArtifactId()); |
|
||||||
dependency.getExcludeRules().add(rule); |
|
||||||
} |
|
||||||
|
|
||||||
private void addImplicitExcludeRules(ModuleDependency dependency) { |
|
||||||
if (isStarter(dependency)) { |
|
||||||
logger.info("Adding implicit managed exclusion rules to starter " |
|
||||||
+ dependency); |
|
||||||
dependency.getExcludeRules().add( |
|
||||||
new DefaultExcludeRule("commons-logging", "commons-logging")); |
|
||||||
dependency.getExcludeRules().add( |
|
||||||
new DefaultExcludeRule("commons-logging", "commons-logging-api")); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private boolean isStarter(ModuleDependency dependency) { |
|
||||||
return (dependency.getGroup() != null |
|
||||||
&& dependency.getGroup().equals("org.springframework.boot") && dependency |
|
||||||
.getName().startsWith("spring-boot-starter")); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,39 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle.exclude; |
|
||||||
|
|
||||||
import org.gradle.api.Project; |
|
||||||
import org.springframework.boot.gradle.PluginFeatures; |
|
||||||
import org.springframework.boot.gradle.SpringBootPluginExtension; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link PluginFeatures} to apply exclusion rules. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
public class ExcludePluginFeatures implements PluginFeatures { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void apply(Project project) { |
|
||||||
SpringBootPluginExtension extension = project.getExtensions().getByType( |
|
||||||
SpringBootPluginExtension.class); |
|
||||||
if (extension.isApplyExcludeRules()) { |
|
||||||
project.getConfigurations().all(new ApplyExcludeRules(project)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,41 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle.resolve; |
|
||||||
|
|
||||||
import org.gradle.api.Action; |
|
||||||
import org.gradle.api.Project; |
|
||||||
import org.gradle.api.artifacts.Configuration; |
|
||||||
import org.springframework.boot.gradle.PluginFeatures; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link PluginFeatures} to add version resolution support. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
public class ResolvePluginFeatures implements PluginFeatures { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void apply(final Project project) { |
|
||||||
project.getConfigurations().all(new Action<Configuration>() { |
|
||||||
@Override |
|
||||||
public void execute(Configuration configuration) { |
|
||||||
SpringBootResolutionStrategy.applyToConfiguration(project, configuration); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,79 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-2014 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.boot.gradle.resolve; |
|
||||||
|
|
||||||
import org.gradle.api.Action; |
|
||||||
import org.gradle.api.Project; |
|
||||||
import org.gradle.api.artifacts.Configuration; |
|
||||||
import org.gradle.api.artifacts.DependencyResolveDetails; |
|
||||||
import org.gradle.api.artifacts.ModuleVersionSelector; |
|
||||||
import org.springframework.boot.dependency.tools.Dependency; |
|
||||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
|
||||||
import org.springframework.boot.gradle.VersionManagedDependencies; |
|
||||||
|
|
||||||
/** |
|
||||||
* A resolution strategy to resolve missing version numbers using the |
|
||||||
* 'spring-boot-dependencies' POM. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
public class SpringBootResolutionStrategy { |
|
||||||
|
|
||||||
private static final String SPRING_BOOT_GROUP = "org.springframework.boot"; |
|
||||||
|
|
||||||
public static void applyToConfiguration(final Project project, |
|
||||||
Configuration configuration) { |
|
||||||
if (VersionManagedDependencies.CONFIGURATION.equals(configuration.getName())) { |
|
||||||
return; |
|
||||||
} |
|
||||||
VersionResolver versionResolver = new VersionResolver(project); |
|
||||||
configuration.getResolutionStrategy().eachDependency(versionResolver); |
|
||||||
} |
|
||||||
|
|
||||||
private static class VersionResolver implements Action<DependencyResolveDetails> { |
|
||||||
|
|
||||||
private final VersionManagedDependencies versionManagedDependencies; |
|
||||||
|
|
||||||
public VersionResolver(Project project) { |
|
||||||
this.versionManagedDependencies = new VersionManagedDependencies(project); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void execute(DependencyResolveDetails resolveDetails) { |
|
||||||
String version = resolveDetails.getTarget().getVersion(); |
|
||||||
if (version == null || version.trim().length() == 0) { |
|
||||||
resolve(resolveDetails); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void resolve(DependencyResolveDetails resolveDetails) { |
|
||||||
ManagedDependencies dependencies = this.versionManagedDependencies |
|
||||||
.getManagedDependencies(); |
|
||||||
ModuleVersionSelector target = resolveDetails.getTarget(); |
|
||||||
if (SPRING_BOOT_GROUP.equals(target.getGroup())) { |
|
||||||
resolveDetails.useVersion(dependencies.getSpringBootVersion()); |
|
||||||
return; |
|
||||||
} |
|
||||||
Dependency dependency = dependencies |
|
||||||
.find(target.getGroup(), target.getName()); |
|
||||||
if (dependency != null) { |
|
||||||
resolveDetails.useVersion(dependency.getVersion()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue