Maven 多仓库和镜像配置

栏目: 服务器 · 发布时间: 6年前

内容简介:设置多仓库有两种方法,第一种直接在项目 POM 中定义这里的 id 就是 mirrorOf 使用的 ID。第二种方法是在

多仓库配置

设置多仓库有两种方法,第一种直接在项目 POM 中定义

<project>
...
  <repositories>
    <repository>
      <id>my-repo1</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
    <repository>
      <id>my-repo2</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
  </repositories>
...
</project>

这里的 id 就是 mirrorOf 使用的 ID。

第二种方法是在 ~/.m2/settings.xml 文件中全局修改。

<settings>
 ...
 <profiles>
   ...
   <profile>
     <id>myprofile</id>
     <repositories>
       <repository>
         <id>my-repo2</id>
         <name>your custom repo</name>
         <url>http://jarsm2.dyndns.dk</url>
       </repository>
       ...
     </repositories>
   </profile>
   ...
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
 ...
</settings>

别忘了激活 profile,或者也可以使用 mvn 参数

mvn -Pmyprofile ...

这里提供一下 jboss 官方的配置

<profiles>
    <profile>
      <id>jboss</id>
      <repositories>
        <repository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Maven Repository Group</name>
          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Maven Repository Group</name>
          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
</profiles>

官方文档

设置镜像

设置镜像的作用是为了加快下载速度,理论上来说任何一个仓库 B 可以提供仓库 A 所有的内容,那么可以认为 B 是 A 的一个镜像,比如说 阿里提供了很多仓库的镜像 使用这些镜像可以提高下载速度。

<mirror>
      <id>mirror</id>
      <mirrorOf>external:*,!repo</mirrorOf>
      <name>nexus repository</name>
      <url>http://nexus.xxx/repository/maven-proxy</url>
</mirror>

说明:

  • id 唯一标识
  • mirrorOf 指定镜像规则,什么情况下从镜像仓库拉取, 官方文档
    *
    external:*
    repo,repo1
    *,!repo1
    
  • name 名称描述
  • url 地址

使用场景

大部分情况下公司或者自用都会自建 nexus 仓库,那么首先 profile 中会配置需要的远程仓库,比如 id 为 repo url 为 http://nexus.xxx.xxx 那么可以在 mirror 中配置 mirrorOf

<mirrorOf>repo</mirrorOf>
<url>指向你自己的搭的代理</url>

这样对 repo 的所有请求都会转发给你自己的 Nexus。

mirrorOf 也有很多其他的语法,可以参考上面。


以上所述就是小编给大家介绍的《Maven 多仓库和镜像配置》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数学之美 (第二版)

数学之美 (第二版)

吴军 / 人民邮电出版社 / 2014-11 / 49.00元

几年前,“数学之美”系列文章原刊载于谷歌黑板报,获得上百万次点击,得到读者高度评价。读者说,读了“数学之美”,才发现大学时学的数学知识,比如马尔可夫链、矩阵计算,甚至余弦函数原来都如此亲切,并且栩栩如生,才发现自然语言和信息处理这么有趣。 在纸本书的创作中,作者吴军博士几乎把所有文章都重写了一遍,为的是把高深的数学原理讲得更加通俗易懂,让非专业读者也能领略数学的魅力。读者通过具体的例子学到的......一起来看看 《数学之美 (第二版)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具