Thursday, January 10, 2013

Resolving External dependencies in Maven

Problem

Lets say we have an external dependency - a jar, a .so file provided to us by a third party, an external team and their files are not available on any public repository, or on the organization's own repository. We are using a maven and need to include this file in our build.

Just to make things more interesting, lets say we have to provide our project to someone outside.

We will look at two simple solutions to resolve this external dependency.

Solutions

1. Standard

Get this external file added to your local repository. Use the following command to install to your machine's local repository, as picked directly from maven docs:

mvn install:install-file  -Dfile=path-to-your-artifact-jar \
                          -DgroupId=your.groupId \
                          -DartifactId=your-artifactId \
                          -Dversion=version \
                          -Dpackaging=jar \
                          -DlocalRepositoryPath=path-to-specific-local-repo


This is very useful indeed, but needs to be done by everyone in the team, and by any person outside the project with whom you'd want to share.

2. Quick and Dirty

Keep the file in any desired location and let any person building project be aware of it. Modify your pom to explicitly have external dependency that is not provided by any repository.


<dependency>
<groupId>Third Party's group Id</groupId>
<artifactId>myCustomJar.artifcatId</artifactId>
<version>myCustomJar.version</version>
<systemPath>C:/customJars/myCustomJar.jar</systemPath>
</dependency>

Here, you explicitly provide the location of dependency, via systemPath tag, and informing people to modify this to where-ever they would like to keep. This would also be so much easier to explain to people who are not-yet maven'ated.

If people in project share a common drive, the path may refer to jar placed on common drive and none in project will have to edit their copy of pom.xml

No comments :

Post a Comment