Maven: Specifying Local Repo

Links on configuring local Maven Repo


Maven offline

You can run maven in offline mode mvn -o install. Of course any artifacts not available in your local repository will fail. Maven is not predicated on distributed repositories, but they certainly make things more seamless. Its for this reason that many shops use internal mirrors that are incrementally synced with the central repos.

In addition, the mvn dependency:go-offline can be used to ensure you have all of your dependencies installed locally before you begin to work offline.

Installing an artifact to a specific local repository path

General information about how to copy jars into your local repository can be found in the Guide to installing 3rd party JARs

By default, the Apache Maven Install Plugin uses the local repository defined in the settings.xml to install an artifact.

You could install an artifact on a specific local repository by setting the localRepositoryPath parameter when installing. 

  1. mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=path-to-your-artifact-jar \
  2. -DgroupId=your.groupId \
  3. -DartifactId=your-artifactId \
  4. -Dversion=version \
  5. -Dpackaging=jar \
  6. -DlocalRepositoryPath=path-to-specific-local-repo

Note: By using the fully qualified path of a goal, you're ensured to be using the preferred version of the maven-install-plugin. When using mvn install:install-file its version depends on its specification in the pom or the version of Apache Maven.

According to the Maven POM Reference and the Guide to using multiple repositories, you can specify repositories in pom.xml too.

There are two different ways that you can specify the use of multiple repositories. The first way is to specify in a POM which repositories you want to use

And according to Introduction to repositories, you can use the file:// protocol in <url>.

Remote repositories refer to any other type of repository, accessed by a variety of protocols such as file:// and http://.

So the following works:

      <name>Example Repository</name>


Based on your comment and edit, you need to override the default repository and Maven home directory in pom.xml.

I've found a topic about disabling central repository, and tried out the answers, but Maven still uses the values from settings.xml. This answer in another thread explains why:

settings.xml allows you to override definitions in pom.xml, not the other way round.

So it's seems it is not possible to override the default mechanism from pom.xml, Maven will search for dependencies in repositories configured in settings.xml and will install to Maven home specified in that file.

    Even with a repository set as above, maven will still, by default, download artifacts from and install artifacts to ~/.m2/repository - IIRC, the above simply specifies a backup to download from and a target to deploy to. I'm looking to change - in the pom.xml - where the system initially searches for artifacts and uses as the destination fro the mvn install command. – drew Aug 4 '18 at 15:12
    I see, please check my edited answer. – juzraai Aug 4 '18 at 15:48
    @juzraai The definition of a repository has nothing to do with the definition of a local cache apart from that it does not make sense to define a repository on file base.... – khmarbaise Aug 5 '18 at 9:40