From 7607bf1ab8be3a2f2a0da526fe08cf5277308998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Mon, 5 Aug 2024 16:05:00 +0200 Subject: [PATCH] Document that repackage should not be used on the command-line This commit clarifies how we intend the spring-boot:repackage goal to be used. As it operates on the source jar (or war) that must be effectively up-to-date to produce an accurate result, the package phase must have run. Contrary to build-image that was designed to be used on the command-line by forking a package lifecycle first, repackage does not do that. This commit also clarifies that by providing a more focused error message. Closes gh-22317 --- .../src/docs/antora/modules/maven-plugin/pages/packaging.adoc | 4 ++++ .../java/org/springframework/boot/maven/RepackageMojo.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/packaging.adoc b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/packaging.adoc index f51cdeb616..1d1fe87d9f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/packaging.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/packaging.adoc @@ -10,6 +10,10 @@ Packaging an executable archive is performed by the `repackage` goal, as shown i include::example$packaging/repackage-pom.xml[tags=repackage] ---- +WARNING: The `repackage` goal is not meant to be used alone on the command-line as it operates on the source +`jar` (or `war`) produced by the `package` phase. +To use this goal on the command-line, you must include the `package` phase: `mvn package spring-boot:repackage`. + TIP: If you are using `spring-boot-starter-parent`, such execution is already pre-configured with a `repackage` execution ID so that only the plugin definition should be added. The example above repackages a `jar` or `war` archive that is built during the package phase of the Maven lifecycle, including any `provided` dependencies that are defined in the project. 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 e3a6534418..1808a6380d 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 @@ -221,6 +221,10 @@ public class RepackageMojo extends AbstractPackagerMojo { private void repackage() throws MojoExecutionException { Artifact source = getSourceArtifact(this.classifier); File target = getTargetFile(this.finalName, this.classifier, this.outputDirectory); + if (source.getFile() == null) { + throw new MojoExecutionException( + "Source file is not available, make sure 'package' runs as part of the same lifecycle"); + } Repackager repackager = getRepackager(source.getFile()); Libraries libraries = getLibraries(this.requiresUnpack); try {