Tuesday, 18 February 2014

Maven - add existing jars to local repository

In order to add existing jars into the local maven repository, please use the command below.

mvn install:install-file -Dfile=${JAR_FULL_PATH} -DgroupId=${UNIQUE_GID}  -DartifactId=${UNIQUE_ARTIFACTID} -Dversion=${VERSION} -Dpackaging=jar 

And add the dependency in pom.xml as follows.

<dependency>
   <groupId>${UNIQUE_GID}</groupId>
   <artifactId>${UNIQUE_ARTIFACTID}</artifactId>
   <version>${VERSION}</version>
</dependency>

The second way to achieve this is to add system scoped dependency with the system path. 

<dependency>
   <groupId>${UNIQUE_GID}</groupId>
   <artifactId>${UNIQUE_ARTIFACTID}</artifactId>
   <version>${VERSION}</version>
   <scope>system</scope>
   <systemPath>${basedir}/${JAR_RELATIVE_PATH}</systemPath>
</dependency> 

Please be cautious about this, since it breaks maven's dependency system. Most probably, you will see a warning in the maven build output as follows.

Some problems were encountered while building the effective model for X
[WARNING] 'dependencies.dependency.systemPath' for X should not point at files within the project directory, ${basedir}/Y will be unresolvable by dependent projects  


Hope it helps.


No comments:

Post a Comment