Maven 多仓库和镜像配置

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

内容简介:设置多仓库有两种方法,第一种直接在项目 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 多仓库和镜像配置》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

奔跑吧,程序员

奔跑吧,程序员

[美]叶夫根尼·布里克曼(Yevgeniy Brikman) / 吴晓嘉 / 人民邮电出版社 / 2018-7 / 99.00元

本书以软件工程师出身的创业者的角度,全面介绍了创业公司该如何打造产品、实现技术和建立团队,既是为创业者打造的一份实用入门指南,又适合所有程序员系统认识IT行业。书中内容分为三部分——技术、产品和团队,详细描绘创业的原始景象,具体内容包括:创业点子、产品设计、数据与营销、技术栈的选择、整洁的代码、软件交付、创业文化、招兵买马,等等。一起来看看 《奔跑吧,程序员》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具