Introduction

The JarJar Plugin for Maven provides mojos to repackage dependencies inside a project artifact to avoid classpath conflicts. It uses code from the official JarJar project.

Description

Jar Jar Links is a utility that makes it easy to repackage Java libraries and embed them into your own distribution. This is useful for two reasons:

  • You can easily ship a single jar file with no external dependencies.
  • You can avoid problems where your library depends on a specific version of a library, which may conflict with the dependencies of another library.

Usage

jarjar

This example is taken from the sisu-guice project, which embeds ASM and CGLIB.

  <build>
    ...
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>jarjar-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jarjar</goal>
            </goals>
            <configuration>
              <includes>
                <include>asm:asm</include>
                <include>org.sonatype.sisu.inject:cglib</include>
              </includes>
              <rules>
                <rule>
                  <pattern>org.objectweb.asm.**</pattern>
                  <result>com.google.inject.internal.asm.@1</result>
                </rule>
                <rule>
                  <pattern>net.sf.cglib.**</pattern>
                  <result>com.google.inject.internal.cglib.@1</result>
                </rule>
                <keep>
                  <pattern>com.google.inject.**</pattern>
                </keep>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    ...