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

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

Closed
paskos opened this issue Nov 16, 2018 · 8 comments
Closed

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

paskos opened this issue Nov 16, 2018 · 8 comments

Comments

@paskos
Copy link

paskos commented Nov 16, 2018

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 runtime
configure jib-maven-plugin plugin
build and run docker image
docker exec -it /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>
[...]
@briandealwis
Copy link
Member

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.

@paskos
Copy link
Author

paskos commented Nov 16, 2018

Thanks for the quick answer. And what about provided dependencies ?

@briandealwis
Copy link
Member

We resolve runtime and system dependencies. So I think provided dependencies will be ignored.

@TadCordle
Copy link
Contributor

Closing since it sounds like things are working as intended.

@paskos
Copy link
Author

paskos commented Nov 29, 2018

Actually I moved to fabric8io docker-maven-plugin because it uses maven-assembly-plugin syntax. It provides excludes capabilities.

@loosebazooka
Copy link
Member

@paskos just curious how your build is now configured?

@paskos
Copy link
Author

paskos commented Nov 29, 2018

@paskos just curious how your build is now configured?

This is a part of my config, it's not working at is is in this message but the full version is.
Notice the assembly, inline part. I was able to exclude the dependencies I didn't want in the image.

<plugin>
   <groupId>io.fabric8</groupId>
   <artifactId>docker-maven-plugin</artifactId>
      <configuration>
      <imagePullPolicy>${docker.image.pull-policy}</imagePullPolicy>
      <images>
        <image>
           <name>${docker.image.name}</name>
           <build>
              <from>${docker.image.from.name}</from>
              <workdir>${docker.home.dir}</workdir>
              <cmd>exec ./scripts/start_micro_service.sh</cmd>
	     <!-- a way to tell Docker how to test a container to check that it’s still working -->
             <healthCheck>
               <cmd>curl -f http://localhost:9090/actuator/health || exit 1</cmd>
               <!-- Check every 10 seconds -->
               <interval>10s</interval>
               <!-- Fail if no response after 1 second -->
               <timeout>1s</timeout>
               <!-- Allow 10 minutes for the container to start before being flagged as unhealthy -->
               <startPeriod>10m</startPeriod>
               <!-- Fail 3 times until the container is considered unhealthy -->
               <retries>3</retries>
             </healthCheck>
           <!-- assembly describing files copied into image -->
           <assembly>
             <targetDir>${docker.home.dir}</targetDir>
             <inline>
               <dependencySets>
                 <dependencySet>
                   <useProjectArtifact>true</useProjectArtifact>
                   <useTransitiveDependencies>false</useTransitiveDependencies>
                   <useTransitiveFiltering>false</useTransitiveFiltering>
                   <unpack>false</unpack>
                   <include>${project.groupId}:${project.artifactId}</include>
                   <scope>runtime</scope>
                 </dependencySet>

                 <dependencySet>
                   <useProjectArtifact>false</useProjectArtifact>
                   <useTransitiveDependencies>true</useTransitiveDependencies>
                   <useTransitiveFiltering>false</useTransitiveFiltering>
                   <unpack>false</unpack>
                   <scope>runtime</scope>
                   <outputDirectory>lib</outputDirectory>
                   <excludes>
                     <exclude>org.springframework.boot:spring-boot-devtools</exclude>
                   </excludes>
                 </dependencySet>
               </dependencySets>
             </inline>
           </assembly>
         </build>
       </image>
     </images>
   </configuration>
[...]
</plugin>

@chanseokoh
Copy link
Member

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

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

No branches or pull requests

5 participants