Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

java - Set the maven local repository location in a pom.xml file?

It's possible to set the maven local repository in settings.xml:

<localRepository>${user.home}/.m2/repository</localRepository>

And it's possible to set the maven local repository on the command line:

mvn clean install -Dmaven.repo.local=repository

Is it possible to specify within the pom.xml itself?

Note: I'd like a way to specify, in the pom.xml, where maven initially searches for artifacts (by default, ~/.m2/repository) and where maven installs artifacts via mvn install (by default, ~/.m2/repository).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...