java - Maven multi-project build with API modules does not seem to include project-level dependencies in build image

Hello I have a springboot multi-project maven build which builds multiple images. The structure is similar to:

- project-parent
   - common
   - project-b-parent
      - project-b-api
      - project-b-gateway
      - project-b-launcher
   - project-c-parent
      - project-c-api
      - project-c-gateway
      - project-c-launcher

Where the *launcher modules are my springboot uber jars and gateways are spring mvc controllers and supporting classes, and apis are project-level dependencies within the launcher modules. for example project-c has a dependency on project-b-api

My project-parent pom has:


Note I've added <jib.skip>true</jib.skip> to my parent pom. I've got <jib.skip>false</jib.skip> in the launchers and this creates the intended behaviour of only creating images from the *launcher modules.

All modules are versioned as 0.0.1-SNAPSHOT.

When I inspect my image using dive I have no SNAPSHOT DEPENDENCIES layer, and my project-level dependencies do not appear to be in the image.

When I run my applications they seem to start up SpringBoot and listen on a port, how ever the controller's end points aren't loaded. Another project throws a NoClassDefFoundError exception when trying to load a class from a project-level dependency.

I've tried versioning everything as 0.0.1 without the SNAPSHOT and my project-level dependencies are not included in my dependency layer.

I have also tried running mvn -X -DjibSerialize=true clean compile jib:build > logs.txt and my class-level dependencies

[INFO] --- jib-maven-plugin:1.0.0:build (default-cli) @ project-b-launcher ---
[DEBUG] Configuring mojo from plugin realm ClassRealm[plugin>, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo '' with basic configurator -->
[DEBUG]   (f) allowInsecureRegistries = true
[DEBUG]   (f) mainClass = project-b.stuff.ApplicationKt
[DEBUG]   (f) container =$ContainerParameters@77662d13
[DEBUG]   (f) image = my.registry/distroless-java:latest
[DEBUG]   (f) from =$FromConfiguration@6a0328d7
[DEBUG]   (f) project = MavenProject: @ C:\my-programs\project-parent\project-b-parent\project-b-launcher\pom.xml
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@51ec2df1
[DEBUG]   (f) skip = false
[DEBUG]   (f) image = my-new-image
[DEBUG]   (f) tags = [0.0.1, latest]
[DEBUG]   (f) to =$ToConfiguration@6370bf52
[DEBUG] -- end configuration --
[INFO] Containerizing application to my.registry\project-parent\project-b-parent\project-b-launcher, my.registry\project-parent\project-b-parent\project-b-launcher\customer-launcher\project-b-launcher:0.0.1-SNAPSHOT, my.registry\project-parent\project-b-parent\project-b-launcher\customer-launcher\project-b-launcher...
[DEBUG] Containerizing application with the following files:
[DEBUG]     Dependencies:
[DEBUG]         C:\my-programs\project-parent\project-c-parent\project-c-gateway\target\classes
[DEBUG]         C:\my-programs\project-parent\project-c-parent\project-c-api\target\classes
[DEBUG]         C:\Users\me\.m2\repository\org\springframework\spring-web\5.1.4.RELEASE\spring-web-5.1.4.RELEASE.jar

Please note I renamed a lot of sensitive directories etc in this DEBUG log output. I'm not sure if the second and third bottom lines (project-level dependencies) are supposed to point to target\classes\ - are they supposed to reference .jars ? I guess they can't if I'm only doing a mvn compile jib:build

I hope I've posted this in the correct place.

1 Answer

  1. Francis- Reply


    It turned out that there have been issues with the OP's project setup. (Details in Basically, both spring-boot-maven-plugin and jib-maven-plugin were applied at the root pom.xml. This results in

    • spring-boot-maven-plugin attempting to create a runnable JAR for each sub-module, some of which are libraries that do not have the main class.
    • jib-maven-plugin attempting to build an image for each sub-module as well as the top project.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>