From bf88a7e466540b2848e83eb35b42b1ced6b5c277 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 27 Nov 2018 15:09:55 +0100 Subject: [PATCH] Be more lenient when repackage is invoked several times This commit makes the repackager more lenient when it is invoked several times in the same lifecycle. Closes gh-15034 --- .../org/springframework/boot/loader/tools/Repackager.java | 6 +++--- .../java/org/springframework/boot/maven/RepackageMojo.java | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java index 651be8294a..4c764dea7d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java @@ -179,11 +179,11 @@ public class Repackager { if (this.layout == null) { this.layout = getLayoutFactory().getLayout(this.source); } - if (alreadyRepackaged()) { - return; - } destination = destination.getAbsoluteFile(); File workingSource = this.source; + if (alreadyRepackaged() && this.source.equals(destination)) { + return; + } if (this.source.equals(destination)) { workingSource = getBackupFile(); workingSource.delete(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index a08f0c8a19..03f56c706d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -245,7 +245,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { private Artifact getArtifact(String classifier) { if (classifier != null) { for (Artifact attachedArtifact : this.project.getAttachedArtifacts()) { - if (classifier.equals(attachedArtifact.getClassifier())) { + if (classifier.equals(attachedArtifact.getClassifier()) + && attachedArtifact.getFile() != null + && attachedArtifact.getFile().isFile()) { return attachedArtifact; } } @@ -335,7 +337,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { if (this.attach) { attachArtifact(source, target); } - else if (source.getFile().equals(target)) { + else if (source.getFile().equals(target) && original.exists()) { String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier : "main artifact"; getLog().info(String.format("Updating %s %s to %s", artifactId,