question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Maven plugin: Skipped dependency module missing from service image

See original GitHub issue

Environment:

  • Jib version: 2.6.0
  • Build tool: Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
  • JVM: 14.0.2, AdoptOpenJDK
  • OS: Linux 5.4.0-52-generic amd64

Description of the issue: Building images from the root folder of a multi-module project, I don’t get functional images: during container startup, the JVM can not find classes from the (skipped) common module

Expected behavior:

Images are functional, i.e. include all dependencies (even if they were marked to “skip” for Jib).

Steps to reproduce:

  1. Maven project with three modules common, serviceA, serviceB; the latter two depend on common (via dependencyManagement in the root POM).
  2. Configure Jib in the root pom.
  3. Run mvn compile jib:dockerBuild

jib-maven-plugin Configuration: Root:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>${jib.version}</version>
    <configuration>
      <skip>true</skip>
      <from>
        <image>gcr.io/distroless/java:11</image>
      </from>
      <to>
        <image>my-service-${project.artifactId}</image>
      </to>
    </configuration>
</plugin>

serviceA, serviceB:

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
          <skip>false</skip>
        </configuration>
      </plugin>

Additional Information: Without <skip>, building in the root folder fails because common doesn’t have a “main” class:

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.5.2:build (default-cli) on project commons: Main class was not found, perhaps you should add a mainClass configuration to jib-maven-plugin

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, Dec 9, 2020

Does Maven not resolve this to the sibling module? 🤷‍♂️

It should. Not sure what’s going on.

So, if I were to run mvn -pl serviceA clean package jib:dockerBuild, it wouldn’t work either because commons would silently be forgotten?

You need -am (--also-make) too. That is, mvn -am -pl serviceA clean package jib:dockerBuild.

--also-make - build the specified projects, and any of their dependencies in the reactor

We have a multi-module example, which I think is configured a little bit different than yours. Worth taking a look.

Let us know if you have any questions. If you have a reproducible sample, we can take a look too.

0reactions
reitzigcommented, Dec 9, 2020

Maybe? We do have this in serviceA/pom.xml:

<dependency>
    <groupId>our.group</groupId>
    <artifactId>commons</artifactId>
</dependency>

Does Maven not resolve this to the sibling module? 🤷‍♂️

Unfortunately, AFAIK, there is no way a plugin can trigger lifecycle phases (whether it be mvn deploy, mvn install, or mvn compile). For your build to run the compile or package lifecycle, you must give the command.

For example, if you don’t run the package phase, Maven will never create common-…jar for your “common” module, which if existed Jib would containerize as a dependency of “serviceA”. Likewise, if you don’t run the compile phase, Maven will not create .class files, and Jib would miss those compile files. It’s not possible for Jib to run package or compile.

Thanks.

So, if I were to run mvn -pl serviceA clean package jib:dockerBuild, it wouldn’t work either because commons would silently be forgotten? Ugn… -pl commons,serviceA it is, but that’s … sad.

Anyway, it seems that by issue is with Maven, not Jib. Thanks for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven Multi-module dependency package not found
I figured it out. The rest-client-microservice is a Spring Boot project and uses the following plugin:
Read more >
fabric8io/fabric8-maven-plugin
Default Enrichers will create a default Service and Deployment (DeploymentConfig for OpenShift) when no other resource objects are provided.
Read more >
Developing and compiling your Quarkus applications with ...
The Quarkus Maven repository contains many of the dependencies that Java developers typically use to build their applications. This procedure ...
Read more >
Apache Maven Dependency Plugin – Usage
If not set, the plugin will attempt to resolve it from the project dependencies and then the dependencyManagement section.
Read more >
Maven Artifactory Plugin - JFrog - JFrog Documentation
The plugin's invocation phase is validate by default and we recommend you don't change it so the plugin is called as early as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found