Browse Source

Produce a single library for multiple file dependencies on the same file

Previously, the Gradle plugin’s ProjectLibraries produced a new library
for every file dependency, even if the dependencies where on the same
file. This would lead to a repackaging failure due to multiple
libraries having the same name.

This commit updates ProjectLibraries to treat file dependencies on the
same file as a single library, thereby resolving the name clash.

Fixes gh-1646
pull/2035/head
Andy Wilkinson 11 years ago
parent
commit
bcd4c8eee2
  1. 30
      spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java
  2. 28
      spring-boot-integration-tests/src/test/resources/multi-project-common-file-dependency/build.gradle
  3. 3
      spring-boot-integration-tests/src/test/resources/multi-project-common-file-dependency/settings.gradle
  4. 0
      spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/build.gradle
  5. 0
      spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/common/lib/foo.jar
  6. 0
      spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/settings.gradle
  7. 17
      spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/ProjectLibraries.java

30
spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java

@ -17,11 +17,9 @@
package org.springframework.boot.gradle; package org.springframework.boot.gradle;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.gradle.tooling.ProjectConnection; import org.gradle.tooling.ProjectConnection;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.boot.dependency.tools.ManagedDependencies;
@ -38,21 +36,31 @@ public class MultiProjectRepackagingTests {
private static final String BOOT_VERSION = ManagedDependencies.get() private static final String BOOT_VERSION = ManagedDependencies.get()
.find("spring-boot").getVersion(); .find("spring-boot").getVersion();
private static ProjectConnection project;
@BeforeClass
public static void createProject() throws IOException {
project = new ProjectCreator().createProject("multi-project-repackage");
}
@Test @Test
public void repackageWithTransitiveFileDependency() throws Exception { public void repackageWithTransitiveFileDependency() throws Exception {
ProjectConnection project = new ProjectCreator()
.createProject("multi-project-transitive-file-dependency");
project.newBuild().forTasks("clean", "build") project.newBuild().forTasks("clean", "build")
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); .withArguments("-PbootVersion=" + BOOT_VERSION).run();
File buildLibs = new File("target/multi-project-repackage/main/build/libs"); File buildLibs = new File(
"target/multi-project-transitive-file-dependency/main/build/libs");
JarFile jarFile = new JarFile(new File(buildLibs, "main.jar")); JarFile jarFile = new JarFile(new File(buildLibs, "main.jar"));
assertThat(jarFile.getEntry("lib/commons-logging-1.1.3.jar"), notNullValue()); assertThat(jarFile.getEntry("lib/commons-logging-1.1.3.jar"), notNullValue());
assertThat(jarFile.getEntry("lib/foo.jar"), notNullValue()); assertThat(jarFile.getEntry("lib/foo.jar"), notNullValue());
jarFile.close(); jarFile.close();
} }
@Test
public void repackageWithCommonFileDependency() throws Exception {
ProjectConnection project = new ProjectCreator()
.createProject("multi-project-common-file-dependency");
project.newBuild().forTasks("clean", "build")
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
File buildLibs = new File(
"target/multi-project-common-file-dependency/build/libs");
JarFile jarFile = new JarFile(new File(buildLibs,
"multi-project-common-file-dependency.jar"));
assertThat(jarFile.getEntry("lib/foo.jar"), notNullValue());
jarFile.close();
}
} }

28
spring-boot-integration-tests/src/test/resources/multi-project-common-file-dependency/build.gradle

@ -0,0 +1,28 @@
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
}
}
subprojects {
apply plugin: 'java'
dependencies {
compile rootProject.files {'lib/foo.jar'}
}
}
apply plugin: 'spring-boot'
springBoot {
mainClass = 'foo.bar.Baz'
}
dependencies {
compile project(':one')
compile project(':two')
}

3
spring-boot-integration-tests/src/test/resources/multi-project-common-file-dependency/settings.gradle

@ -0,0 +1,3 @@
include 'one'
include 'two'

0
spring-boot-integration-tests/src/test/resources/multi-project-repackage/build.gradle → spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/build.gradle

0
spring-boot-integration-tests/src/test/resources/multi-project-repackage/common/lib/foo.jar → spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/common/lib/foo.jar

0
spring-boot-integration-tests/src/test/resources/multi-project-repackage/settings.gradle → spring-boot-integration-tests/src/test/resources/multi-project-transitive-file-dependency/settings.gradle

17
spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/ProjectLibraries.java

@ -199,6 +199,23 @@ class ProjectLibraries implements Libraries {
return name; return name;
} }
@Override
public int hashCode() {
return getFile().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof GradleLibrary) {
return getFile().equals(((GradleLibrary) obj).getFile());
}
return false;
}
@Override
public String toString() {
return getFile().getAbsolutePath();
}
} }
/** /**

Loading…
Cancel
Save