jib icon indicating copy to clipboard operation
jib copied to clipboard

Add support to read from `configuration.outputDirectory` parameter in the spring-boot-maven-plugin

Open hellozin opened this issue 3 years ago • 7 comments

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

hellozin avatar Jul 26 '21 05:07 hellozin

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

elefeint avatar Jul 29 '21 16:07 elefeint

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.)

chanseokoh avatar Jul 29 '21 21:07 chanseokoh

I would like to work on this issue.

RandyLovevivi avatar Apr 12 '22 10:04 RandyLovevivi

@RandyLovevivi Sure, we would love to have some contributions from the society. Let us know if you need any help!

ddixit14 avatar Apr 12 '22 14:04 ddixit14

Hey @RandyLovevivi, are you still working on this issue?

AnvarKhatik avatar Sep 27 '22 05:09 AnvarKhatik

@AnvarKhatik there hasn't been much activity on this issue for a while so we're happy to review your contribution if you're interested in taking it on.

mpeddada1 avatar Oct 05 '22 14:10 mpeddada1

@mpeddada1 @ddixit14 can I pick up this issue ?

Abhijeetmishr avatar Feb 16 '23 10:02 Abhijeetmishr