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.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, 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.)
1reaction
elefeintcommented, Jul 29, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot get resources folder into jar when using spring boot ...
Im trying to build an executable jar that runs with spring boot, but I cant get the spring xml from the resources folder...
Read more >
Spring Boot Maven Plugin Documentation
It allows you to package executable jar or war archives, run Spring Boot applications, generate build information and start your Spring Boot ...
Read more >
Maven JAR plugin skipping generated-resources folder ...
Related Query · cannot get resources folder into jar when using spring boot maven plugin · Maven JAR plugin skipping generated-resources folder ·...
Read more >
Running a Spring Boot App with Maven vs an Executable Jar
Get started with Spring 5 and Spring Boot 2, through the Learn Spring ... the Spring Boot Maven plugin is the recommended tool...
Read more >
Apache Maven Dependency Plugin – dependency:copy ...
(example /outputDirectory/junit-3.8.1-jar ) Default value is: false . User property is: mdep.useSubDirectoryPerArtifact .
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