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.

Do no include runtime/provided/optional maven dependencies in image

See original GitHub issue

Description: I am working on a spring-boot project and I have a runtime dependency on spring-boot-devtools that is used during development. When I build the image using jib-maven-plugin spring-boot-devtools is copied in /libs directory even if the scope is runtime.

Expected: I expected the jar to be ignored the same way spring-boot maven plugin does not include it in the fat jar.

Step to reproduce: Create a maven project add a dependency with <scope>runtime</scope> configure jib-maven-plugin plugin build and run docker image docker exec -it <container> /bin/bash list the content of the libs/ directory the runtime dependency will be in the directory

Environment: jib-maven-plugin: version 0.10.0 OS: Mac OS X Maven: version 3.5.4 java: version 1.8.0_181

jib-maven-plugin Configuration:

[...]
<dependencies>
    <dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
	<optional>true</optional>
	<scope>runtime</scope>
    </dependency>
</dependencies>
<build>
<plugins>
<plugin>
   <groupId>com.google.cloud.tools</groupId>
   <artifactId>jib-maven-plugin</artifactId>
   <version>${jib-maven-plugin.version}</version>
     <configuration>
       <from>
          <image>${docker.registry.host}/${docker.from.image}</image>
          <credHelper>ecr-login</credHelper>
       </from>
       <to>
          <image>${docker.registry.host}/${project.artifactId}:${build.number}</image>
          <credHelper>ecr-login</credHelper>
          <tags>
             <tag>${build.number}</tag>
             <tag>latest</tag>
           </tags>
         </to>
         <container>
            <appRoot>${docker.root.dir}</appRoot>
            <mainClass>${main.class}</mainClass>
             <useCurrentTimestamp>${docker.use-current-timestamp}</useCurrentTimestamp>
           </container>
        </configuration>
   </plugin>
</plugins>
</build>
[...]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
briandealwiscommented, Nov 16, 2018

The Maven docs for runtime says:

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

Although you’ve marked spring-boot-devtools as optional, the docs say:

Optional dependencies - If project Y depends on project Z, the owner of project Y can mark project Z as an optional dependency, using the “optional” element. When project X depends on project Y, X will depend only on Y and not on Y’s optional dependency Z. The owner of project X may then explicitly add a dependency on Z, at her option. (It may be helpful to think of optional dependencies as “excluded by default.”)

Which I interpret to mean that any project that depends on your project won’t pull in spring-boot-devtools. But spring-boot-devtools is still a dependency for your project and will be pulled in.

I think you’ll need to use a Maven profile if you want to exclude spring-boot-devtools.

0reactions
chanseokohcommented, Jul 27, 2020

For those coming to this thread to find a way to exclude spring-too-devtools, see #2336.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven – Optional Dependencies and Dependency Exclusions
If a user wants to use functionality related to an optional dependency, they have to redeclare that optional dependency in their own project....
Read more >
Maven docker cache dependencies - Stack Overflow
I am trying to build an image which encapsulates the repository/dependencies so I can run the image anywhere, without needing to first prepare...
Read more >
Caching Maven Dependencies with Docker - Baeldung
This approach lets us keep the final Docker image smaller since it won't contain Maven executables or our source code.
Read more >
Maven dependencies | IntelliJ IDEA Documentation - JetBrains
IntelliJ IDEA lets you manage Maven dependencies in your project. You can add, import Maven dependencies, view them in the diagram, ...
Read more >
Spring Boot Maven Plugin Documentation
The plugin can create executable archives (jar files and war files) that contain all of an application's dependencies and can then be run...
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