Maven – Include system scope dependency in maven-assembly-plugin

If you don’t have Maven repository server like Archiva or Nexus, you may need to include those libs which are not public on the internet in your Maven project and specifiy the dependency scope as system in the pom.xml. The following example includes the eureka-0.0.1.jar which is located in the folder called external on project root.

...
<dependency>
  <groupId>ykyuen.info</groupId>
  <artifactId>eureka</artifactId>
  <version>0.0.1</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/external/eureka-0.0.1.jar</systemPath>
</dependency>
...

 

A few months ago i wrote a blog post about how to package the project jar file with all dependencies.
Maven – Package the jar file with dependencies

Please note that if you have system scope dependencies, they would not be included during the assembly as mentioned in the above blog post.

A workaround is instead of using system scope, we could make use of the maven-install-plugin to in install the external jars to the machine local Maven repository before the build. So you can remove the <scope> and <systemPath> in your dependency setting such that the it will use the default compile scope just like other dependencies.

...
<dependency>
  <groupId>ykyuen.info</groupId>
  <artifactId>eureka</artifactId>
  <version>0.0.1</version>
</dependency>
...

 

Then add the maven-install-plugin in the pom.xml as well.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-install-plugin</artifactId>
  <executions>
    <execution>
      <id>install-external</id>
      <phase>clean</phase>
      <configuration>
        <file>${basedir}/external/eureka-0.0.1.jar</file>
        <repositoryLayout>default</repositoryLayout>
        <groupId>ykyuen.info</groupId>
        <artifactId>eureka</artifactId>
        <version>0.0.1</version>
        <packaging>jar</packaging>
        <generatePom>true</generatePom>
      </configuration>
      <goals>
        <goal>install-file</goal>
      </goals>
    </execution>
  </executions>
</plugin>

 

We could only attach the install process in the clean life cycle otherwise Maven requires all dependencies to be resolved before executing. So the external lib is not present in the local Maven repo, you have to install it through

mvn clean

 

Then you can start packing as normal.

mvn package

 

Please note that the above workaround violates the Maven practice so i would suggest setting up a repository server to cache the public artifacts and manage your own libs as well.

Done =)

Reference:

Advertisements

2 thoughts on “Maven – Include system scope dependency in maven-assembly-plugin”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s