Skip to content

Commit 1ffdc90

Browse files
committed
Further enhancements to Gradle repackaging logic
This commit refines the changes made under 4be688a. 4be688a 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
1 parent fdc3d70 commit 1ffdc90

File tree

1 file changed

+14
-5
lines changed
  • spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.util.HashSet;
22+
import java.util.Set;
2123
import java.util.concurrent.TimeUnit;
2224

2325
import org.gradle.api.Action;
@@ -139,15 +141,22 @@ public void execute(Jar jarTask) {
139141

140142
private boolean isTaskMatch(Jar task, Object withJarTask) {
141143
if (withJarTask == null) {
142-
return isDefaultJarTask(task);
144+
if ("".equals(task.getClassifier())) {
145+
Set<Object> tasksWithCustomRepackaging = new HashSet<Object>();
146+
for (RepackageTask repackageTask : RepackageTask.this.getProject()
147+
.getTasks().withType(RepackageTask.class)) {
148+
if (repackageTask.getWithJarTask() != null) {
149+
tasksWithCustomRepackaging
150+
.add(repackageTask.getWithJarTask());
151+
}
152+
}
153+
return !tasksWithCustomRepackaging.contains(task);
154+
}
155+
return false;
143156
}
144157
return task.equals(withJarTask) || task.getName().equals(withJarTask);
145158
}
146159

147-
private boolean isDefaultJarTask(Jar jarTask) {
148-
return "jar".equals(jarTask.getName());
149-
}
150-
151160
private void repackage(File file) {
152161
File outputFile = RepackageTask.this.outputFile;
153162
if (outputFile != null && !file.equals(outputFile)) {

0 commit comments

Comments
 (0)