Set the maven local repository location in a pom.xml file?
If the problem is having to write the options every time when running maven, you can use a feature available since version 3.3.1 that allows you to set command line options in your project (or parent project of your module). Read @Brice's answer: https://stackoverflow.com/a/48583079
So with this feature in mind, you can achieve a similar result by setting up a new settings.xml
with the <localRepository>
pointing to the location you desire and use maven.config
in your project to make maven use the new settings.xml
, which by the way can be anywhere you want.
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:
<project>
...
<repositories>
<repository>
<id>example-repo</id>
<name>Example Repository</name>
<url>file://path/to/your/local/repository</url>
</repository>
</repositories>
</project>
Edit:
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 inpom.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.