在pom.xml文件中设置Maven本地存储库位置? [英] Set the maven local repository location in a pom.xml file?

查看:446
本文介绍了在pom.xml文件中设置Maven本地存储库位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在settings.xml中设置Maven本地存储库:

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

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

并且可以在命令行上设置Maven本地存储库:

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

mvn clean install -Dmaven.repo.local=repository

是否可以在pom.xml本身中指定?

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

注意:我想在pom.xml中指定一种方法,其中maven最初在其中搜索工件(默认情况下为~/.m2/repository),而maven在其中通过mvn install安装工件(默认情况下为~/.m2/repository). ).

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

推荐答案

根据 Maven POM参考使用多个存储库的指南,也可以在pom.xml中指定存储库.

According to the Maven POM Reference and the Guide to using multiple repositories, you can specify repositories in pom.xml too.

可以使用两种不同的方法来指定多个存储库的使用.第一种方法是在POM中指定要使用的存储库

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

根据存储库简介,您可以使用<url>中的file://协议.

And according to Introduction to repositories, you can use the file:// protocol in <url>.

远程存储库是指任何其他类型的存储库,可以通过各种协议(例如file://和http://)进行访问.

Remote repositories refer to any other type of repository, accessed by a variety of protocols such as file:// and http://.

因此,以下工作有效:

<project>
  ...
  <repositories>
    <repository>
      <id>example-repo</id>
      <name>Example Repository</name>
      <url>file://path/to/your/local/repository</url>
    </repository>
  </repositories>
</project>


根据您的评论和编辑,您需要覆盖pom.xml中的默认存储库和Maven主目录.

Based on your comment and edit, you need to override the default repository and Maven home directory in pom.xml.

我找到了有关禁用中央存储库的主题,并尝试了答案,但是Maven仍使用settings.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允许您覆盖pom.xml中的定义,而不是相反.

settings.xml allows you to override definitions in pom.xml, not the other way round.

因此似乎无法从pom.xml中覆盖默认机制,Maven将在settings.xml中配置的存储库中搜索依赖项,并将安装到该文件中指定的Maven主页中.

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.

这篇关于在pom.xml文件中设置Maven本地存储库位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆