From 4b135ada5068b5b8d015b6bcca9ca12fd8274de4 Mon Sep 17 00:00:00 2001 From: Julien Oncelay Date: Thu, 28 Mar 2019 15:49:19 +0100 Subject: [PATCH 1/4] Add project output jar to the generated MANIFEST This is to resolve #476 --- .../dist/service/JavaServiceDistributionPlugin.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java index 7c04af317..16c5e7bfe 100644 --- a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java +++ b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java @@ -32,6 +32,7 @@ import org.gradle.api.InvalidUserCodeException; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.JavaExec; @@ -85,8 +86,13 @@ public void apply(Project project) { task.setAppendix("manifest-classpath"); task.doFirst(t -> { - String classPath = project.getConfigurations().getByName("runtimeClasspath") - .getFiles() + + FileCollection runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath"); + + TaskProvider jarTask = project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME); + FileCollection jarOutputs = jarTask.get().getOutputs().getFiles(); + + String classPath = runtimeClasspath.plus(jarOutputs).getFiles() .stream() .map(File::getName) .collect(Collectors.joining(" ")); From 24d947731256a7bbf03a885ec868af7c44935950 Mon Sep 17 00:00:00 2001 From: Julien Oncelay Date: Thu, 28 Mar 2019 15:54:47 +0100 Subject: [PATCH 2/4] Assert presence of project jar in jar MANIFEST Test for resolution of #476 --- .../dist/service/ServiceDistributionPluginTests.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/ServiceDistributionPluginTests.groovy b/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/ServiceDistributionPluginTests.groovy index ebe95413f..8085a71f4 100644 --- a/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/ServiceDistributionPluginTests.groovy +++ b/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/ServiceDistributionPluginTests.groovy @@ -525,8 +525,12 @@ class ServiceDistributionPluginTests extends GradleIntegrationSpec { def classpathJar = file('dist/service-name-0.0.1/service/lib/').listFiles() .find({ it.name.endsWith("-manifest-classpath-0.0.1.jar") }) classpathJar.exists() - readFromZip(classpathJar, "META-INF/MANIFEST.MF") - .contains('Class-Path: guava-19.0.jar root-project-manifest-') // etc + + def zipManifest = readFromZip(classpathJar, "META-INF/MANIFEST.MF").replace('\r\n ','') + zipManifest.contains('Class-Path: ') + zipManifest.contains('guava-19.0.jar') + zipManifest.contains('root-project-manifest-classpath-0.0.1.jar') + zipManifest.contains('root-project-0.0.1.jar') } def 'does not produce manifest-classpath jar when disabled in extension'() { From d6e401d0caf7943a6587a2b49db31cc2ba02e695 Mon Sep 17 00:00:00 2001 From: Julien Oncelay Date: Thu, 28 Mar 2019 16:10:23 +0100 Subject: [PATCH 3/4] Fix style --- .../gradle/dist/service/JavaServiceDistributionPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java index 16c5e7bfe..70c134f11 100644 --- a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java +++ b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java @@ -89,7 +89,8 @@ public void apply(Project project) { FileCollection runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath"); - TaskProvider jarTask = project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME); + TaskProvider jarTask = project.getTasks().withType(Jar.class) + .named(JavaPlugin.JAR_TASK_NAME); FileCollection jarOutputs = jarTask.get().getOutputs().getFiles(); String classPath = runtimeClasspath.plus(jarOutputs).getFiles() From 31a3d147ed3efdfda7cdefb7fdb8b8ba3e763e77 Mon Sep 17 00:00:00 2001 From: Julien Oncelay Date: Thu, 28 Mar 2019 18:23:04 +0100 Subject: [PATCH 4/4] Inline jarTask --- .../gradle/dist/service/JavaServiceDistributionPlugin.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java index 70c134f11..178641ff1 100644 --- a/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java +++ b/gradle-sls-packaging/src/main/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPlugin.java @@ -89,9 +89,8 @@ public void apply(Project project) { FileCollection runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath"); - TaskProvider jarTask = project.getTasks().withType(Jar.class) - .named(JavaPlugin.JAR_TASK_NAME); - FileCollection jarOutputs = jarTask.get().getOutputs().getFiles(); + FileCollection jarOutputs = project.getTasks().withType(Jar.class) + .getByName(JavaPlugin.JAR_TASK_NAME).getOutputs().getFiles(); String classPath = runtimeClasspath.plus(jarOutputs).getFiles() .stream()