Maven存储库镜像 [英] maven repository mirrors

查看:81
本文介绍了Maven存储库镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我在Maven settings.xml

Normally, I have the following mirror configured in my Maven settings.xml

<mirror>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
  <mirrorOf>*</mirrorOf>
</mirror>

我的理解是,该镜像阻止Maven从Internet下载依赖项,即,它将仅在此内部存储库中查找依赖项.

My understanding is that this mirror prevents Maven from downloading dependencies from the internet, i.e. it will only look for them in this internal repository.

但是,每当我要添加此内部存储库中不存在的依赖项时,都必须注释掉上面的文本,并将以下内容添加到项目的pom.xml

However, whenever I want to add a dependency that isn't in this internal repository, I have to comment out the text above and add the following to the project's pom.xml

<repository>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
</repository>

当我进行这些更改时,Maven将检查本地存储库中的依赖项,如果找不到,请将其从Internet下载到本地存储库.有了所需的依赖关系后,然后将配置更改回去.

When I make these changes Maven will check for dependencies in the local repo, and if not found, download them from the internet to the local repo. Once I have the dependencies I need, I then change my configuration back.

是否有一种方法可以获取所需的行为-始终检查内部存储库,然后检查公共(Internet)存储库-不必在每个项目的pom.xml中添加<repository>?

Is there a way to get the behaviour I want - always check the internal repo, then the public (Internet) repos - without having to add the <repository> to every project's pom.xml?

理想情况下,我想在settings.xml中指定一次此存储库,但是看来您只能在此配置镜像.

Ideally I would like to specify this repository once in settings.xml, but it seems that you can only configure mirrors there.

推荐答案

您可以尝试将maven配置为仅将镜像用于中央存储库,或排除由某些ID标识的存储库.

You could try to configure maven to use the mirror only for the central repository or to exclude the repository identified by some id.

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>central</mirrorOf>
</mirror>

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>*,!internal-repository</mirrorOf>
</mirror>

这些示例改编自 maven设置 查看全文

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