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

Cannot find JAR in outputDirectory path when using spring-boot-maven-plugin #3356

Open
hellozin opened this issue Jul 26, 2021 · 2 comments
Open

Comments

@hellozin
Copy link

@hellozin hellozin commented Jul 26, 2021

Environment:

  • Jib version: 3.1.2
  • Build tool: Maven 3.6.3
  • OS: mac OS 10.15.7(19H2)

Description of the issue:

When I build(or dockerBuild) with below configuration shows up this error message.
Obtaining project build output files failed; make sure you have packaged your project before trying to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean package jib:build"?)

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.3.2.RELEASE</version>
  <configuration>
    <outputDirectory>lib</outputDirectory>
  </configuration>
</plugin>
$ mvn clean package jib:dockerBuild
...
Caused by: java.io.IOException: Obtaining project build output files failed; make sure you have packaged your project before trying to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean package jib:build"?)
...
Caused by: java.nio.file.NoSuchFileException: /path/to/my-project/target/my-application.jar.original

Build success when remove configuration.outputDirectory.
It seems not read outputDirectory configuration if spring-boot-maven-plugin is used.
(I guessed by looking at this code.)

Is it intended behavior?

Expected behavior:
Build success when using outputDirectory in spring-boot-maven-plugin

Steps to reproduce:

  1. use spring-boot-maven-plugin
  2. set outputDirectory
  3. mvn clean package jib:dockerBuild
@elefeint elefeint added the p2 label Jul 28, 2021
@elefeint
Copy link
Contributor

@elefeint elefeint commented Jul 29, 2021

@hellozin Thank you for the report! We are trying to reproduce the issue.

@chanseokoh
Copy link
Member

@chanseokoh chanseokoh commented Jul 29, 2021

It's a bug (or limitation) in that the output directory is unaccounted for. Note that Jib doesn't use the repackaged Spring Boot fat JAR but a standard thin-JAR packaged by maven-jar-plugin. The current code to read Spring Boot configuration is just to correctly find the path for the thin-JAR (because the Spring Boot plugin renames the original JAR before replacing it). Some workarounds:

  1. Don't do "packaged" containerization. That is, remove <containerizingMode>packaged. We normally recommend the non-packaged mode unless there is a specific reason, because the non-packaged mode builds a bit more optimized image.
  2. Don't set <outputDirectory> in spring-boot-maven-plugin. Jib won't make use of a Spring Boot fat JAR anyway.
  3. Set <outputDirectory> in maven-jar-plugin to match the directory set in spring-boot-maven-plugin, e.g.,
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>
            <outputDirectory>lib</outputDirectory>
          </configuration>
        </plugin>
    (You may need to run mvn package once more.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants