Maven jib does not work in multimodule project

532 views Asked by At

I have a multimodule app like this:

parent
+ lib_one
+ lib_two
+ spring-parent
  + spring-config
  + spring-app

Now i want to build the spring-app module with google jib. I have added this to the plugin section of my parent-pom:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.4.0</version>
    <configuration>
      <from>
        <image>eclipse-temurin:21-jre-ubi9-minimal</image>
      </from>
      <to>
        <image>DOCKERIMAGE</image>
        <tags>
          <tag>${project.version}</tag>
          <tag>latest</tag>
        </tags>
     </to>
     <container>
      <ports>
        <port>8080</port>
      </ports>
    </container>
  </configuration>
</plugin>

Every submodule which contains no container target get these to avoid jib to be executed:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <skip>true</skip>
  </configuration>
</plugin>

The module spring-app get this with <skip>false</skip> and a -config.

If i run maven clean compile jib:build from the root dir i got these exception:

Obtaining project build output files failed; make sure you have compiled your project before tryi
ng to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean compile jib:build"?)

Does any one know what i am doing wrong?

I'm using java 21 and spring boot 3.1.

Greetings from Germany!

1

There are 1 answers

0
Chanseok Oh On

You should set <skip>true</skip> for the Jib plugin in all modules (including the root pom.xml) but spring-app.

Just in case, I am talking about skipping jib-maven-plugin. Skipping spring-boot-maven-plugin as you did won't prevent from Jib from running, since it's just a different plugin.

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
          <!-- we don't want jib to execute on this module -->
          <skip>true</skip>
        </configuration>
      </plugin>

The Jib repository hosts a multi-module example project with this setup. For example, the root pom.xml and the shared-library sub-module skip the Jib plugin.