From 1ffdc90f04f3e01426d18927c664d1d80c64e3e7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 3 Jul 2014 13:31:34 +0100 Subject: [PATCH] Further enhancements to Gradle repackaging logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit refines the changes made under 4be688aa. 4be688aa made the default jar task a special case which broke repackaging of the archive produced by the default war task. This commit refines RepackageTask’s logic so that, when it’s enabled, it will repackage a jar task’s archive if: - The jar task is equal to RepackageTask.withJarTask - The name of the jar task is equal to RepackageTask.withJarTask - RepackageTask.withJarTask is null, the jar task is not referenced by another RepackageTask’s withJarTask, and the jar task has an empty classifier The last of these three is the default case and ensures the, when the Spring Boot plugin is applied, default jar and war artifacts are repackaged. The classifier check is required to prevent default source and javadoc artifacts from being repackaged. Fixes #1204 --- .../boot/gradle/repackage/RepackageTask.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java index 9125875590..7f5e5b5614 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java @@ -18,6 +18,8 @@ package org.springframework.boot.gradle.repackage; import java.io.File; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.gradle.api.Action; @@ -139,15 +141,22 @@ public class RepackageTask extends DefaultTask { private boolean isTaskMatch(Jar task, Object withJarTask) { if (withJarTask == null) { - return isDefaultJarTask(task); + if ("".equals(task.getClassifier())) { + Set tasksWithCustomRepackaging = new HashSet(); + for (RepackageTask repackageTask : RepackageTask.this.getProject() + .getTasks().withType(RepackageTask.class)) { + if (repackageTask.getWithJarTask() != null) { + tasksWithCustomRepackaging + .add(repackageTask.getWithJarTask()); + } + } + return !tasksWithCustomRepackaging.contains(task); + } + return false; } return task.equals(withJarTask) || task.getName().equals(withJarTask); } - private boolean isDefaultJarTask(Jar jarTask) { - return "jar".equals(jarTask.getName()); - } - private void repackage(File file) { File outputFile = RepackageTask.this.outputFile; if (outputFile != null && !file.equals(outputFile)) {