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:

   ...
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
   </parent>
   <version>0.0.1-SNAPSHOT</version>
   <groupId>my.group</groupId>
   <artifactId>project-parent</artifactId>
   <packaging>pom</packaging>
   ...
   <modules>
        <module>project-b-parent</module>
        <module>project-c-parent</module>
    </modules>
    ...
    <properties>
        <jib.skip>true</jib.skip>
    </properties>
    ...
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.google.cloud.tools</groupId>
                        <artifactId>jib-maven-plugin</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <from>
                                <image>my.base.image:latest</image>
                            </from>
                            <to>
                                <image>my.image.registry/${project-name}</image>
                                <tags>
                                    <tag>${project.version}</tag>
                                    <tag>latest</tag>
                                </tags>
                            </to>
                            <allowInsecureRegistries>true</allowInsecureRegistries>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

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 com.google.cloud.tools:jib-maven-plugin:1.0.0:build from plugin realm ClassRealm[plugin>com.google.cloud.tools:jib-maven-plugin:1.0.0, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo 'com.google.cloud.tools:jib-maven-plugin:1.0.0:build' with basic configurator -->
[DEBUG]   (f) allowInsecureRegistries = true
[DEBUG]   (f) mainClass = project-b.stuff.ApplicationKt
[DEBUG]   (f) container = com.google.cloud.tools.jib.maven.JibPluginConfiguration$ContainerParameters@77662d13
[DEBUG]   (f) image = my.registry/distroless-java:latest
[DEBUG]   (f) from = com.google.cloud.tools.jib.maven.JibPluginConfiguration$FromConfiguration@6a0328d7
[DEBUG]   (f) project = MavenProject: my.company:project-a-launcher:0.0.1 @ 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 = com.google.cloud.tools.jib.maven.JibPluginConfiguration$ToConfiguration@6370bf52
[DEBUG] -- end configuration --
[INFO] 
[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

    2019-11-14

    It turned out that there have been issues with the OP's project setup. (Details in https://github.com/GoogleContainerTools/jib/issues/1539.) 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>