Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classpath file (/app/jib-classpath-file) doesn't match libs folder if libraries have same artifactId/version #3331

Closed
davinkevin opened this issue Jul 1, 2021 · 4 comments · Fixed by #3336

Comments

@davinkevin
Copy link

davinkevin commented Jul 1, 2021

Environment:

  • Jib version: 3.1+ (3.1.0 and 3.1.1)
  • Build tool: maven 3.6.3
  • OS: MacOS 10.16

Description of the issue:

In our project, we have two dependencies with the groupId as only difference:

        <dependency>
            <groupId>com.name.app1</groupId>
            <artifactId>rest-client</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.name.app2</groupId>
            <artifactId>rest-client</artifactId>
            <version>2.0.0</version>
        </dependency>

Both are, in this case, in the same version (which never happened before).

If I run the application, I end up with ClassNotFoundException.

If I dig a little in the application, I can see the following results:

> $ docker run -it --entrypoint=/busybox/sh --rm my-custom-image:1.2.3
~ $ ls /app/libs/ | grep rest-client
rest-client-2.0.0-187729.jar
rest-client-2.0.0-54224.jar
~ $ cat /app/jib-classpath-file | sed 's/:/\n/g' | grep rest-client
/app/libs/rest-client-2.0.0.jar
/app/libs/rest-client-2.0.0.jar

To sumarize, jib is working well at lib level to add a suffix at the end of the jar in the /app/libs folder to avoid a filename clash at filesystem level.

But, if we look at the /app/jib-classpath-file to represent the classpath for our app, the hash is not integrated and none of the dependency can be resolved by our app leading to a ClassNotFoundException.

The expected behavoir would be to launch the app with the correct classpath, so to generate correctly the /app/jib-classpath-file.

If you need more information, let me know 😇.

@davinkevin davinkevin changed the title Classpath file (/app/jib-classpath-file) doesn't match libs folder if library has the same artifactId/version Classpath file (/app/jib-classpath-file) doesn't match libs folder if libraries have same artifactId/version Jul 1, 2021
@suztomo
Copy link
Contributor

suztomo commented Jul 1, 2021

I want to reproduce the case. Do you know a pair of Maven artifact coordinates (in Maven Central) which has the same artifactId and version?

@chanseokoh
Copy link
Member

chanseokoh commented Jul 1, 2021

This is a bug in Jib. We'll work on fixing this, but it seems a bit tricky at the same time.

Workarounds:

  1. Downgrade to 3.0 (so that it doesn't use the classpath argument file)
  2. Set jib.container.entrypoint yourself in the traditional way with .../libs/*, e.g.,
<container>
  <entrypoint>java,-cp,/app/resources:/app/classes:/app/libs/*,@/app/jib-main-class-file</entrypoint>
</container>

or specifying the main class as well like

<container>
  <entrypoint>java,-cp,/app/resources:/app/classes:/app/libs/*,com.example.YourMainClass</entrypoint>
</container>

BTW, Maven supports another format for a string list:

  <entrypoint>
    <arg>java</arg>
    <arg>-cp</arg>
    <arg>/app/resources:/app/classes:/app/libs/*</arg>
    <arg>@/app/jib-main-class-file</arg>
  </entrypoint>

@davinkevin
Copy link
Author

I did downgrade the jib module to 3.0.0. This was the easiest solution while waiting for a fix.

Thank you for your support.

@chanseokoh
Copy link
Member

@davinkevin @orevial @pgillet @VixsTy we released Jib build plugins 3.1.2 which should fix this. Try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants