Dark theme | Light theme

June 27, 2008

Change settings file for Maven

Maven uses the settings.xml file from ${user.home}/.m2. I was working on a project lately and I wanted to have a different local repository, but didn't want to change it in ${user.home}/.m2/settings.xml, because it would interfere with my other projects. So I copied the settings.xml from ${user.home]/.m2 and changed the location of the local repository.

But how do we get this settings active when we run Maven? We can use the system property org.apache.maven.user-settings and point it to our new file. So we can run maven like mvn install -Dorg.apache.maven.user-settings=/users/dev/new_settings.xml and the new local repository is used.

To make sure we don't have to type it in every time we can use the environment variable MAVEN_OPTS. Everything we assign to this variable will be added to the mvn command line. So for Windows we do set MAVEN_OPTS=-Dorg.apache.maven.user-settings and now we can run mvn install and still the new local repository will be used.