We've noticed that when we run the build-image goal as part of our maven lifecycle, the entire lifecycle runs twice (compile, test-compile, report, etc). This is not an issue for most plugins, since they detect ths behaviour and will simply not run again. However, we have some reporting plugins that will generate incorrect reports due to this behaviour.
Is there a way to disable it? And why does it happen?
Edit: https://github.com/Luckl/spring-boot-maven-test with a very basic example.
The reason why most of the lifecycle is being run twice, is because the "build-image" goal in Spring Boot Maven plugin requires the package phase to be run beforehand. In the logs you can see that Maven executes this phase in a fork:
[INFO] >>> spring-boot-maven-plugin:2.3.0.RELEASE:build-image (default-cli) > package @ spring-boot-maven-test >>>
As far as I know Maven does not have a system in place to skip running that phase again when it already has run in that same build (when this annotation is used).
What you could do to circumvent this is to not bind the build-image goal in the regular Maven lifecycle, but rather call it directly:
mvn spring-boot:build-image
. The result will be that the plugin triggers the package phase, and afterwards builds the docker image.If you need to add reporting plugins to your build you could add that to the package lifecycle (which then also will be built as prerequisite to build-image), or you could call a separate mvn command afterwards (where you could skip/include certain plugins with profiles).
Update: A PR has been submitted to fix this in Maven, follow the links to GitHub from here: https://issues.apache.org/jira/browse/MNG-6566