Commit 1ffdc90f authored by Andy Wilkinson's avatar Andy Wilkinson

Further enhancements to Gradle repackaging logic

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
parent fdc3d70c
...@@ -18,6 +18,8 @@ package org.springframework.boot.gradle.repackage; ...@@ -18,6 +18,8 @@ package org.springframework.boot.gradle.repackage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.gradle.api.Action; import org.gradle.api.Action;
...@@ -139,15 +141,22 @@ public class RepackageTask extends DefaultTask { ...@@ -139,15 +141,22 @@ public class RepackageTask extends DefaultTask {
private boolean isTaskMatch(Jar task, Object withJarTask) { private boolean isTaskMatch(Jar task, Object withJarTask) {
if (withJarTask == null) { if (withJarTask == null) {
return isDefaultJarTask(task); if ("".equals(task.getClassifier())) {
Set<Object> tasksWithCustomRepackaging = new HashSet<Object>();
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); return task.equals(withJarTask) || task.getName().equals(withJarTask);
} }
private boolean isDefaultJarTask(Jar jarTask) {
return "jar".equals(jarTask.getName());
}
private void repackage(File file) { private void repackage(File file) {
File outputFile = RepackageTask.this.outputFile; File outputFile = RepackageTask.this.outputFile;
if (outputFile != null && !file.equals(outputFile)) { if (outputFile != null && !file.equals(outputFile)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment