Skip to content

Instantly share code, notes, and snippets.

@shawmanz32na
Last active March 2, 2017 21:28
Show Gist options
  • Save shawmanz32na/e87cf9ac34a6c4e5a17808f7bf75b960 to your computer and use it in GitHub Desktop.
Save shawmanz32na/e87cf9ac34a6c4e5a17808f7bf75b960 to your computer and use it in GitHub Desktop.
POM snippet to use a local directory as a maven repo

Local Maven Repository

This should give you a gist of how to use a directory inside your project as a maven repository for libraries that aren't published to a public repository.

As written, this will point to the [project-root]/lib directory, which should be formatted in standard maven repository format. You'll "install" new libraries to this directory using the mvn install:install-file task.

The examples below assume we'll be installing shawmans-lib-0.1.2.jar version 0.1.2 with groupId com.shawmanz32na and artifactId lib (determined from the source, which is structured like src/main/java/com/shawmanz32na/lib/code.java).

Usage

Initial setup

Paste the code from local-maven-repo.pom to your project's POM.

Adding new third-party libraries

Install the library to the local Maven repository

From the root of your project:

mvn install:install-file -Dfile=YOUR_JAR.jar -DgroupId=YOUR_GROUP_ID -DartifactId=YOUR_ARTIFACT_ID -Dversion=YOUR_VERSION -Dpackaging=jar -DlocalRepositoryPath=lib

e.g.

mvn install:install-file -Dfile="C:\Users\shawmanz32na\Downloads\shawmans-lib-0.1.2.jar" -DgroupId="com.shawmanz32na" -DartifactId="lib" -Dversion="0.1.2" -Dpackaging="jar" -DlocalRepositoryPath="lib"

Add the library as a dependency to the project

In the project POM, add a new dependency:

  <dependencies>
    ...
    <dependency>
      <groupId>YOUR_GROUP_ID</groupId>
      <artifactId>YOUR_ARTIFACT_ID</artifactId>
      <version>YOUR_VERSION</version>
    </dependency>
    ...
  </dependencies>

e.g.

  <dependencies>
    ...
    <dependency>
      <groupId>com.shawmanz32na</groupId>
      <artifactId>lib</artifactId>
      <version>0.1.2</version>
    </dependency>
    ...
  </dependencies>
<project ...>
<dependencies>
<!-- This dependency gets 'installed' to the local repository using `mvn install:install-file -Dfile="C:\Users\shawmanz32na\Downloads\shawmans-lib-0.1.2.jar" -DgroupId="com.shawmanz32na" -DartifactId="lib" -Dversion="0.1.2" -Dpackaging="jar" -DlocalRepositoryPath="lib"` -->
<dependency>
<groupId>com.shawmanz32na</groupId>
<artifactId>lib</artifactId>
<version>0.1.2</version>
</dependency>
</dependencies>
<!-- This repository exists inside the source, and will contain 3rd party dependencies not available through Maven Central -->
<repositories>
<repository>
<id>third-party-repo</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment