user1052610
user1052610

Reputation: 4719

Building a dependencies jar with Maven

Currently our maven build includes all the dependencies in the jar, using jar-with-dependencies.

We want to split this into two separate jars, one with the project application code and files, and one with the dependencies.

How is this done?

Thanks

Upvotes: 0

Views: 60

Answers (2)

gclaussn
gclaussn

Reputation: 1796

Use the maven-shade-plugin instead with following configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <finalName>${project.artifactId}-${project.version}-libs</finalName>
    <artifactSet>
      <excludes>
        <exclude>${project.groupId}:${project.artifactId}</exclude>
      </excludes>
    </artifactSet>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
    </execution>
  </executions>
</plugin>

The trick is to define a specific final name. This avoids the replacement of the default jar, which is packaged by the maven-jar-plugin. The default name is ${project.artifactId}-${project.version}. So simply add a suffix like libs. Then exclude the artifact itself, because the classes should not be packaged twice.

The build will result in two jar files:

  1. ${project.artifactId}-${project.version}.jar, containing the classes and files of the project
  2. ${project.artifactId}-${project.version}-libs.jar, containing the content of all the dependencies

Upvotes: 0

user1717259
user1717259

Reputation: 2883

This is done using the maven Assembly plugin

http://maven.apache.org/plugins/maven-assembly-plugin/

Upvotes: 1

Related Questions