How to build docker image for multi-module spring boot application using Jib

2k Views Asked by At

I have a Spring boot application which has many modules like error module, persistency, controllers etc like below

--Application
  |
  -- error module
  |
  -- controllers module
  |
  -- Persistancy module
  |
  -- .....

To build docker image for this using Maven jib plugin with below configuration in pom.xml

    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <to>
            <image>some.repo.io/my_name/jib-test</image>
          </to>
          <container>
            <mainClass>com.a.b.c.Application</mainClass>
            <ports>
              <port>8080</port>
            </ports>
          </container>
        </configuration>
    </plugin>

Build is successful. But when I run the image, its throwing error Error: Could not find or load the main class com.a.b.c.Application.

How can I build the image using Jib ?. What am I missing here?

1

There are 1 best solutions below

0
On

In your pom.xml, add:

<modules>
    <module>error</module>
    <module>controllers </module>
    <module>Persistancy </module>
</modules>

Then run the following from your terminal:

mvn -Pprod verify com.google.cloud.tools:jib-maven-plugin:dockerBuild