Maven Local Repository is a feature provided in Maven that allows you to manage local copies of your project’s dependencies. By default, Maven makes a copy of each dependency artifact that is used in your project and stores it in the local repository.

  • macOS/Users/{username}/.m2/repository
  • Linux/home/{username}/.m2/repository
  • Windowsc:Users{username}.m2repository

Customize Maven Local Repository

The settings.xml is the main configuration file of Maven. It is available for user-level or system-level configurations.

  • Global level: Is available at ${MAVEN_HOME}/conf/settings.xml is applied for all Maven users on the system that share the same installation.
  • User level: Can be found at ${HOME}/.m2/settings.xml. This is the user-specific configuration and overrides the global configuration.

To customize the local repository, edit settings.xml and change directory location with tag.

<settings xmlns=“http://maven.apache.org/SETTINGS/1.2.0”

          xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

          xsi:schemaLocation=“http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd”>

  /opt/maven_local_repo

The configuration file looks like the below:

Where is the Maven Local Repository? General Articles
Maven local repository location

Define Maven Local Repository at Command Line

Changes made in settings.xml applied for all commands. We can also specify the local repository as a command line parameter using the maven.repo.local option. which allows us to pass the local repository location as a command-line parameter:

mvn -Dmaven.repo.local=/opt/maven_local_repository install 

Conclusion

In this tutorial, you have learned about setting the local repository path in Maven. This local repository is used to store project artifacts.