skip to Main Content

Two simple questions:

  1. Why is a Spring Boot application executed while creating a Docker image with the mvnw spring-boot:build-image command?
  2. Is there a command line option to prevent this from happening?

I am building a Docker image for a Spring Boot application. The application depends on other, third party services which are not necessarily (and also shouldn’t be) available during the image build process. Hence, the image build fails, since the Spring Boot application checks those third party dependencies on start-up and tries to reconnect until they become available. Side remark: the latter cannot be changed since this is built-in in the framework for the third party service being used.

I also don’t understand why the application should actually be started to build a Docker image.

Thank you for responding and possibly the additional background information.

2

Answers


  1. Chosen as BEST ANSWER

    I found out an alternative approach might be to add an application.properties file in the src/test/resources folder in which you add axon.axonserver.enabled=false

    Doing so allows you to run tests without having a running Axon Server instance available.

    This is probably not the best possible solution, but for now, it does the trick ;-)


  2. I suspect that it’s not the application itself that’s being started, but its tests.

    The build-image goal is bound to the package phase of Maven’s lifecycle. To execute a goal in a particular phase, Maven has to execute every goal in each preceding phase first. The default lifecycle consists of the following phases:

    • validate – validate the project is correct and all necessary information is available
    • compile – compile the source code of the project
    • test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
    • package – take the compiled code and package it in its distributable format, such as a JAR.
    • verify – run any checks on results of integration tests to ensure quality criteria are met
    • install – install the package into the local repository, for use as a dependency in other projects locally
    • deploy – done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

    As you can see, validate, compile, and test all come before package.

    You can skip the tests – at the risk of building an image that doesn’t work – by invoking Maven with -DskipTests.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search