码迷,mamicode.com
首页 > 其他好文 > 详细

setting.xml中mirror和repository的关系

时间:2019-06-19 15:09:58      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:远程   理解   出现   led   官网   vat   nap   dir   下载   

这两天在连公司的两个不同的私服,但是总是出现JAR包不能全部下载下来的问题。经过查资料,大概有了点理解,记录下

1、Jar包分布

    公司的快照JAR全放在http://*:8081/*/libs-snapshot上

   其他第三方包全放在http://*:8081/*/libs-public-local上

2、问题描述

  不能同时从两个地方下载到所有的JAR包

3、问题解决

  经过不断的摸索和查询信息,最终能同时从两个地方拉取JAR包,配置如下:

<mirrors>
      <mirror>
          <id>snapshots</id>
          <mirrorOf>snapshot</mirrorOf>
          <name>snapshots</name>
          <url>http://*:8081/*/libs-snapshot</url>
      </mirror>
      <mirror>
          <id>public</id>
          <mirrorOf>*,!snapshot</mirrorOf>
          <name>public</name>
          <url>http://*:8081/*/libs-public-local</url>
      </mirror>
  </mirrors>

 

<profiles>
    <profile>
      <id>xyz</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
            <id>libs-public</id>
            <name>libs-public</name>
            <url>http://*:8081/*/libs-public-local</url>
        </repository>
        <repository>
          <id>snapshot</id>
          <url>http://*:8081/*/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>ali</id>
          <url>http://maven.aliyun.com/nexus/content/groups/public</url>
          <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        
      </pluginRepositories>
    </profile>
<activeProfiles>
    <activeProfile>xyz</activeProfile>
  </activeProfiles>

4、个人理解

 在配置多个远程仓库的时候,需要借助repository和mirror来配置,仓库指定了什么样的包走这个仓库ID进行下载,而mirror则对仓库进行了地址代理,对应ID的包都走这个镜像。

其中 mirrorof配置非常关键,指定了仓库ID,其配置有多种,可以看官网,简单摘抄点

    * = everything 所有的仓库都走这个镜像
    external:* = everything not on the localhost and not file based. 不在本地,且不一file: 开头的东东,反正是外部的
    repo,repo1 = repo or repo1  或
    *,!repo1 = everything except repo1 出repo1仓库之外的其他仓库

另外,网上还有种说法是:配置了mirror,repository就不起作用了,我觉得可能说法有问题,当且仅当mirrorof配置成  *  时,才是那样的结果,其实也不是不起作用了,只不过mirror把所有repository都给“代理”了。另一种说法是多个mirror时,只有第一次才生效,其实也不完全正确,只有当所有的mirrorof相同的时候,说法才正确。官网的说法是

Note that there can be at most one mirror for a given repository. In other words, you cannot map a single repository to a group of mirrors that all define the same <mirrorOf> value. Maven will not aggregate the mirrors but simply picks the first match.

还有,当mirrorof不能精确匹配时,maven会选取第一个镜像

When Maven looks for a mirror of some repository, it first checks for a mirror whose <mirrorOf> exactly matches the repository identifier. If no direct match is found, Maven picks the first mirror declaration that matches according to the rules above (if any). Hence, you may influence match order by changing the order of the definitions in the settings.xml

5、遗留问题

  在setting中配置多个仓库后,maven怎么分配哪个包从哪个仓库下呢,我大概知道点是配置repository的 Activation。但是不知道的是如果不配置Activation(如下例),那怎么区分呢,希望知道的小伙伴说下,多谢了

什么时候走 public? 什么时候走ali
<repository>
    <id>libs-public</id>
    <name>libs-public</name>
    <url>http://*:8081/*/libs-public-local</url>
</repository>
<repository>
  <id>ali</id>
  <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</repository>

 

setting.xml中mirror和repository的关系

标签:远程   理解   出现   led   官网   vat   nap   dir   下载   

原文地址:https://www.cnblogs.com/lngo/p/11051148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!