The Spring Boot build plugins support creating native images out of the box using the build-image command that uses Buildpacks to build the GraalVM native image. Still, Boot 3.0 has introduced a dedicated build profile native that rather uses the native-maven-plugin which requires GraalVM and the native plugin installed locally.
I would appreciate if one could build images without having to declare an extra profile with boilerplate setup to use the Boot plugin built in functionality to build a Docker container with a native image contained.
Comment From: snicoll
Maybe the native profile should not add an execution. I wonder if ./mvnw native:build should be used rather than package. This way we could configure the buildpack settings in the same profile and you could chose which one to use based on the goal.
Comment From: sdeleuze
Invoking ./mvnw native:build will not build the JAR used as input, resulting to a Execution default-cli of goal org.graalvm.buildtools:native-maven-plugin:0.9.13:build failed: Cannot invoke "java.io.File.exists()" because "artifactFile" is null on a fresh build or after a clean, or leading to potentially generating a native executable not in sync with the sources. Without execution configuration, you have to run ./mvnw package native:build which is not convenient.
That said, just running ./mvnw -Pnative spring-boot:build-image to build a native image would be a convenient and consistent behavior. Is technically possible given the fact it is "outside of Maven lifecycle" (if I am not mistaken)?
See also partially related issue #31782 for the wider context of native integration in Buildpacks.
Comment From: snicoll
We've decided to remove the execution of NBT in the native profile so that users can opt-in to either NBT or Buildpacks. This isn't really transparent at the moment as NBT requires to specify a phase on the command-line (see https://github.com/graalvm/native-build-tools/issues/273) and our integration does not. As part of promoting this work, we should also fix https://github.com/spring-projects/spring-boot/issues/26455
Comment From: snicoll
See #31782