Changing the location of your local Maven repository

By default Apache Maven puts your local repository under the users home drive ${user.home}/.m2/repository.

Generally this isn’t too much of an issue, however if you work off roaming profiles in windows or your home drive is stored on a network drive this can sometimes be undesirable as the repository can get fairly large. Therefore you may want to re-locate it to an alternative location.

This can be fairly easily achieved by defining the location in your ${user.home}/.m2/settings.xml file. If this file does not exist then create one and add the following content to it.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>/path/to/local/repo/</localRepository>
</settings>

More information on this can be found in the Apache Maven documentation here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.