Skip to content

Instantly share code, notes, and snippets.

@dschulz
Last active June 8, 2020 16:31
Show Gist options
  • Save dschulz/86746333c885422a8f673fa6e7081ae6 to your computer and use it in GitHub Desktop.
Save dschulz/86746333c885422a8f673fa6e7081ae6 to your computer and use it in GitHub Desktop.

Project-local maven repository

Purpose

Be able to add third party dependencies not available from conventional repositories. Primarily intended for including Hypersistence Optimizer dependency in a clean way, avoiding warnings during a Maven build that arise from using <scope>system</scope> in the dependency section.

Note: The Hypersistence Optimizer maven-install.sh script does the same as what's described here, just omits creating a subdirectory in the project base directory. Here the suggested subdirectory is 3rdpartylibs.

Adding libraries to this repository

To add a jar artifact to this repository

Create a 3rdpartylibs directory in the ${project.baseDir}

cd /project/baseDir
mkdir 3rdpartylibs

Provided that Maven is installed and available and that the Hypersistence Optimizer zip distribution was unzipped in /full/path/to/unzipped/, install the desired jar file to the project-local repository from the terminal window:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \
  -Dfile=/full/path/to/unzipped/hypersistence-optimizer-2.1.1.jar \
  -DgroupId=io.hypersistence \
  -DartifactId=hypersistence-optimizer \
  -Dversion=2.1.1 \
  -Dpackaging=jar \
  -DgeneratePom=true \
  -DlocalRepositoryPath=3rdpartylibs

Optionally but recommended, source and javadoc jars can be added by including -Dsources=... and -Djavadoc=... respectively:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \
  -Dfile=/full/path/to/unzipped/hypersistence-optimizer-2.1.1.jar \
  -Djavadoc=/full/path/to/unzipped/hypersistence-optimizer-2.1.1-javadoc.jar \
  -Dsources=/full/path/to/unzipped/hypersistence-optimizer-2.1.1-sources.jar \
  -DgroupId=io.hypersistence \
  -DartifactId=hypersistence-optimizer \
  -Dversion=2.1.1 \
  -Dpackaging=jar \
  -DgeneratePom=true \
  -DlocalRepositoryPath=3rdpartylibs

This is needed once and the changes should be commited to the SCM.

Using libraries from this repository

In the project's POM, add a new repository

<repository>
    <id>local-repository</id>
    <url>file://${project.basedir}/3rdpartylibs</url>
</repository>

After adding the repository definition, the library will be available and can be added as a dependency

<dependency>
    <groupId>io.hypersistence</groupId>
    <artifactId>hypersistence-optimizer</artifactId>
    <version>2.1.1</version>
    <optional>true</optional>
</dependency>

The project should now build successfully without warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment