Initialize DependencyResolutionContext with default dependency mgmt

In the absence of a @GrabMetadata annotation,
DependencyResolutionContext provided no dependency management. This
was leading to incorrect dependency versions being pulled in. This
commit intializes the context with default dependency management that
will be replaced should @GrabMetadata be encountered.

Fixes #1021
This commit is contained in:
Andy Wilkinson 2014-06-03 15:57:36 +01:00
parent 0def7644c2
commit 156dadaebe
4 changed files with 28 additions and 7 deletions

View File

@ -26,7 +26,7 @@ import org.springframework.boot.dependency.tools.ManagedDependencies;
/**
* Context used when resolving dependencies.
*
*
* @author Andy Wilkinson
* @since 1.1.0
*/
@ -43,6 +43,8 @@ public class DependencyResolutionContext {
public DependencyResolutionContext(
ArtifactCoordinatesResolver artifactCoordinatesResolver) {
this.artifactCoordinatesResolver = artifactCoordinatesResolver;
this.managedDependencies = new ManagedDependenciesFactory()
.getManagedDependencies();
}
public void setManagedDependencies(ManagedDependencies managedDependencies) {
@ -50,7 +52,7 @@ public class DependencyResolutionContext {
managedDependencies);
this.managedDependencies = new ArrayList<Dependency>(
new ManagedDependenciesFactory(managedDependencies)
.getManagedDependencies());
.getManagedDependencies());
}
public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() {

View File

@ -25,8 +25,9 @@ import static org.junit.Assert.assertThat;
/**
* Integration tests to exercise and reproduce specific issues.
*
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class ReproIntegrationTests {
@ -58,6 +59,12 @@ public class ReproIntegrationTests {
containsString("{\"message\":\"Hello World\"}"));
}
@Test
public void dataJpaDependencies() throws Exception {
this.cli.run("data-jpa.groovy");
assertThat(this.cli.getOutput(), containsString("Hello World"));
}
@Test
public void jarFileExtensionNeeded() throws Exception {
this.thrown.expect(IllegalStateException.class);

View File

@ -45,7 +45,7 @@ public class AetherGrapeEngineTests {
private final AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(
this.groovyClassLoader, Arrays.asList(new RepositoryConfiguration("central",
URI.create("http://repo1.maven.org/maven2"), false)),
new DependencyResolutionContext());
new DependencyResolutionContext());
@Test
public void dependencyResolution() {
@ -54,7 +54,7 @@ public class AetherGrapeEngineTests {
this.grapeEngine.grab(args,
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
assertEquals(6, this.groovyClassLoader.getURLs().length);
assertEquals(5, this.groovyClassLoader.getURLs().length);
}
@Test
@ -76,7 +76,7 @@ public class AetherGrapeEngineTests {
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"),
createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE"));
assertEquals(4, this.groovyClassLoader.getURLs().length);
assertEquals(3, this.groovyClassLoader.getURLs().length);
}
@Test
@ -101,7 +101,7 @@ public class AetherGrapeEngineTests {
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
assertEquals(0, this.groovyClassLoader.getURLs().length);
assertEquals(6, customClassLoader.getURLs().length);
assertEquals(5, customClassLoader.getURLs().length);
}
@Test

View File

@ -0,0 +1,12 @@
@Grab('spring-boot-starter-data-jpa')
@Grab('h2')
class Sample implements CommandLineRunner {
// No Data JPA-based logic. We just want to check that the dependencies are
// resolved correctly and that the app runs
@Override
void run(String... args) {
println "Hello World"
}
}