MAVEN EXPERIENCE - Maven - Use local jars as dependencies

Introduction

Sometime we have a bunch of local jars (e.g. coming out from legacy project) that we want to reuse as dependency in our maven project allowing to share them between developer team.

To do this we can choose from three different tecniques

Deploy to remote maven repository

This is the canonical way. Whether you have a possibility to deploy to an online maven repository do that using the maven-deploy-plugin as shown below.
The full usage statement of the deploy-file mojo can be described as:

mvn deploy:deploy-file -Durl=my_repo_url \
-DrepositoryId=some.id \
-Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=test] \
[-DgeneratePom=true] \
[-DgeneratePom.description="My Project Description"] \
[-DrepositoryLayout=legacy] \
[-DuniqueVersion=false]

Create a local maven repository in a project folder and deploy jars within it

Below the required steps to implement such tecnique

  1. Create a local folder ${project.basedir}/mvn-repo
  2. Install each jar using maven-install-plugin
    > cd mvn-repo
    > mvn install:install-file \
    -DgroupId=mygroupId \
    -DartifactId=myartifactid \
    -Dversion=myversion \
    -Dpackaging=jar \
    -DlocalRepositoryPath=. \
    -Dfile=full_path_of_jar_file
    
    Whether you have a lot of dependencies to install, the better way is create a shell script to perform this operation
  3. Add in you pom reference to local repo
    pom.xml
    <repositories>
    <repository>
    <id>my-local-repo</id>
    <name>my local repo</name>
    <url>file://${basedir}/mvn-repo</url>
    </repository>
    </repositories>
    
    

Copy Jars in a project folder using scope system and systemPath tag DEPRECATED in Maven3

TO DO

Labels

maven maven Delete
dependencies dependencies Delete
housekeeping housekeeping Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.