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:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.IOException;
|
||||
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ProjectCreator {
|
||||
|
||||
public ProjectConnection createProject(String name) throws IOException {
|
||||
File projectDirectory = new File("target/" + name);
|
||||
projectDirectory.mkdirs();
|
||||
|
||||
File gradleScript = new File(projectDirectory, "build.gradle");
|
||||
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"),
|
||||
gradleScript);
|
||||
|
||||
GradleConnector gradleConnector = GradleConnector.newConnector();
|
||||
((DefaultGradleConnector) gradleConnector).embedded(true);
|
||||
return gradleConnector.forProjectDirectory(projectDirectory).connect();
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.tooling.BuildException;
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -33,14 +31,14 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.boot.dependency.tools.ManagedDependencies;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.boot.gradle.ProjectCreator;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests for the various starter projects to check that they don't pull in unwanted
|
||||
* transitive dependencies when used with Gradle
|
||||
*
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@@ -76,15 +74,7 @@ public class StarterDependenciesIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
File projectDirectory = new File("target/starter-dependencies");
|
||||
projectDirectory.mkdirs();
|
||||
|
||||
File gradleScript = new File(projectDirectory, "build.gradle");
|
||||
FileCopyUtils.copy(new File("src/test/resources/build.gradle"), gradleScript);
|
||||
|
||||
GradleConnector gradleConnector = GradleConnector.newConnector();
|
||||
((DefaultGradleConnector) gradleConnector).embedded(true);
|
||||
project = gradleConnector.forProjectDirectory(projectDirectory).connect();
|
||||
project = new ProjectCreator().createProject("starter-dependencies");
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
||||
Reference in New Issue
Block a user