Make repackage depend on jar tasks from runtime project dependencies

By default, when building a project's jar its runtime dependencies
are not taken into account as they are not needed to successfully
compile the code that will be packaged in the jar. A side-effect of
this was that, if a project that was being repackaged had a runtime
dependency on another project, then the repackaged jar would not
include the jar of the project on which it has the runtime dependency
as the jar had not been built.

This commit updates Boot's repackage task to have a dependency on the
jar task of any project dependencies in the runtime configuration
thereby ensuring that those dependencies' jars will have been built
before the repackaging occurs.

Fixes gh-2344
This commit is contained in:
Andy Wilkinson
2015-01-21 15:02:10 +00:00
parent bbd2486c04
commit 93b2a17fb8
4 changed files with 50 additions and 5 deletions

View File

@@ -63,4 +63,17 @@ public class MultiProjectRepackagingTests {
assertThat(jarFile.getEntry("lib/foo.jar"), notNullValue());
jarFile.close();
}
@Test
public void repackageWithRuntimeProjectDependency() throws Exception {
ProjectConnection project = new ProjectCreator()
.createProject("multi-project-runtime-project-dependency");
project.newBuild().forTasks("clean", "build")
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
File buildLibs = new File(
"target/multi-project-runtime-project-dependency/projectA/build/libs");
JarFile jarFile = new JarFile(new File(buildLibs, "projectA.jar"));
assertThat(jarFile.getEntry("lib/projectB.jar"), notNullValue());
jarFile.close();
}
}

View File

@@ -0,0 +1,22 @@
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
}
}
project(':projectA') {
apply plugin: 'spring-boot'
dependencies {
runtime project(':projectB')
}
bootRepackage {
mainClass 'com.foo.Bar'
}
}
project(':projectB') {
apply plugin: 'java'
}

View File

@@ -0,0 +1 @@
include 'projectA', 'projectB'