Question

I have a Jenkins build server that automatically builds the project into a jar when a new commit has been pushed to the GitHub project. I looked at file size of the artifacts that Jenkins creates and I was surprised. I came to the conclusion that all the third-party dependencies were included in the jar artifact!

I don't need Maven to include them in the artifact as that will increase the size dramatically and it isn't useful. So I fiddled around with my pom.xml file, but I couldn't get it working. The dependencies keep being included in the jar.

I'm relatively new to Maven and I would appreciate it a lot if someone can help me out!

Sources (if you need any):

Was it helpful?

Solution

You can avoid packaging your dependencies inside your jar file by providing the scope they should be wrapped in. But since I looked to your pom.xml descriptor and find nothing misconfigured, I will suggest to use the maven-jar-plugin to exclude all third party libraries as follows:

<project>
 ...
<build>
<plugins>
   ...
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>${maven-jar-plugin.version}</version>
    <configuration>
      <excludes>
        <exclude>*.jar</exclude>
      </excludes>
    </configuration>
  </plugin>
  ...
</plugins>
</build>
...
</project>

Hope this helps. BR.

OTHER TIPS

My guess is that this is the root cause:

<resource>
  <directory>libs</directory>
  <excludes>
<exclude>**/*.java</exclude>
  </excludes>
</resource>

if you (also) have all your jars in this folder, then they will end up on the classpath ( see target/classes ), hence they will be part of the jar. You only have to specify the jars as dependencies, Maven will do the rest. Resources are used for non-java (or non-compilable) files, which should end up at the classpath as well, like config files for Spring or Hibernate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top