Add support for building an image without forking the Maven lifecycle

This commit adds a new "build-image-no-fork" goal that behaves exactly
as "build-image", except it does not fork the lifecycle. This is a
common pattern in maven plugins where a goal can be invoked on the
command-line and conveniently make sure that a certain phase has run
prior to its execution.

The new goal is suitable for binding the goal in a phase, typically
package, and rely on it rather than invoking the goal. This makes sure
that the lifecycle is forked, which would run everything again.

Closes gh-26455
This commit is contained in:
Stephane Nicoll
2022-11-21 13:05:23 +01:00
parent efa8d8b877
commit a7f57091a6
29 changed files with 139 additions and 48 deletions

View File

@@ -1,7 +1,8 @@
[[build-image]]
= Packaging OCI Images
The plugin can create an https://github.com/opencontainers/image-spec[OCI image] from a jar or war file using https://buildpacks.io/[Cloud Native Buildpacks] (CNB).
Images can be built using the `build-image` goal.
Images can be built on the command-line using the `build-image` goal.
This makes sure that the package lifecycle has run before the image is created.
NOTE: For security reasons, images build and run as non-root users.
See the {buildpacks-reference}/reference/spec/platform-api/#users[CNB specification] for more details.
@@ -14,6 +15,10 @@ It is possible to automate the creation of an image whenever the `package` phase
include::../maven/packaging-oci-image/pom.xml[tags=packaging-oci-image]
----
NOTE: Use `build-image-no-fork` when binding the goal to the package lifecycle.
This goal is similar to `build-image` but does not fork the lifecycle to make sure `package` has run.
In the rest of this section, `build-image` is used to refer to either the `build-image` or `build-image-no-fork` goals.
TIP: While the buildpack runs from an <<packaging,executable archive>>, it is not necessary to execute the `repackage` goal first as the executable archive is created automatically if necessary.
When the `build-image` repackages the application, it applies the same settings as the `repackage` goal would, that is dependencies can be excluded using one of the exclude options, and Devtools is automatically excluded by default (you can control that using the `excludeDevtools` property).
@@ -209,6 +214,7 @@ You can override this behaviour as shown in the <<build-image.examples.builder-c
For more details, see also <<build-image.examples,examples>>.
include::goals/build-image.adoc[leveloffset=+1]
include::goals/build-image-no-fork.adoc[leveloffset=+1]

View File

@@ -12,7 +12,7 @@
<executions>
<execution>
<goals>
<goal>build-image</goal>
<goal>build-image-no-fork</goal>
</goals>
</execution>
</executions>