mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Further enhancements to Gradle repackaging logic
This commit refines the changes made under4be688aa
.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
This commit is contained in:
parent
fdc3d70cd5
commit
1ffdc90f04
@ -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<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);
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user