https://my.oschina.net/qjx1208/blog/201085

摘要: 记录settings.xml的配置,理解mirror、repository、profile的关系

本地仓库是远程仓库的一个缓冲和子集,当你构建Maven项目的时候,首先会从本地仓库查找资源,如果没有,那么Maven会从远程仓库下载到你本地仓库。这样在你下次使用的时候就不需要从远程下载了。如果你所需要的jar包版本在本地仓库没有,而且也不存在于远程仓库,Maven在构建的时候会报错,这种情况可能发生在有些jar包的新版本没有在Maven仓库中及时更新。

Maven缺省的本地仓库地址为${user.home}/.m2/repository 。也就是说,一个用户会对应的拥有一个本地仓库。当然你可以通过修改${user.home}/.m2/settings.xml 配置这个地址:

Xml代码

  1. <settings>

  2. <localRepository> D:/java/repository</localRepository>

  3. </settings>

如果你想让所有的用户使用统一的配置那么你可以修改Maven主目录下的setting.xml:

${M2_HOME}/conf/setting.xml

repository是指在局域网内部搭建的repository,它跟central repository, jboss repository等的区别仅仅在于其URL是一个内部网址 
mirror则相当于一个代理,它会拦截去指定的远程repository下载构件的请求,然后从自己这里找出构件回送给客户端。配置mirror的目的一般是出于网速考虑。

不过,很多internal repository搭建工具往往也提供mirror服务,比如Nexus就可以让同一个URL,既用作internal repository,又使它成为所有repository的mirror。

高级的镜像配置: 
1.<mirrorOf>*</mirrorOf> 
匹配所有远程仓库。 这样所有pom中定义的仓库都不生效
2.<mirrorOf>external:*</mirrorOf> 
匹配所有远程仓库,使用localhost的除外,使用file://协议的除外。也就是说,匹配所有不在本机上的远程仓库。 
3.<mirrorOf>repo1,repo2</mirrorOf> 
匹配仓库repo1和repo2,使用逗号分隔多个远程仓库。 
4.<mirrorOf>*,!repo1</miiroOf> 
匹配所有远程仓库,repo1除外,使用感叹号将仓库从匹配中排除。

mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性,id是唯一标识一个mirror就不多说了,name貌似没多大用,相当于描述,url是官方的库地址,mirrorOf代表了一个镜像的替代位置,例如central就表示代替官方的中央库。

我本以为镜像库是一个分库的概念,就是说当a.jar在第一个mirror中不存在的时候,maven会去第二个mirror中查询下载。但事实却不是这样,当第一个mirror中不存在a.jar的时候,并不会去第二个mirror中查找,甚至于,maven根本不会去其他的mirror地址查询。

后来终于知道,maven的mirror是镜像,而不是“分库”,只有当前一个mirror无法连接的时候,才会去找后一个,类似于备份和容灾。

还有,mirror也不是按settings.xml中写的那样的顺序来查询的。

所谓的第一个并不一定是最上面的那个。

当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">     <servers>
        <server>
            <id>repo-iss</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>     <mirrors>
        <!-- osc镜像 -->
        <mirror>
            <!-- 镜像所有远程仓库,但不包括指定的仓库 -->
            <id>mirror-osc</id>
            <mirrorOf>external:*,!repo-osc-thirdparty,!repo-iss</mirrorOf>
            <url>http://maven.oschina.net/content/groups/public/</url>
        </mirror>
<!--
        <mirror>
            <id>mirror-iss</id>
            <mirrorOf>external:*</mirrorOf>
            <url>http://10.24.16.99:5555/nexus/content/groups/public/</url>
        </mirror>
-->
    </mirrors>     <profiles>
        <profile>
            <id>profile-default</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>repo-osc-thirdparty</id>
                    <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
            <id>profile-iss</id>
            <repositories>
                <repository>
                    <id>repo-iss</id>
                    <url>http://10.24.16.99:5555/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>repo-iss</id>
                    <url>http://10.24.16.99:5555/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>     <activeProfiles>
        <activeProfile>profile-default</activeProfile>
        <!--<activeProfile>profile-iss</activeProfile>-->
    </activeProfiles> <!--
    <proxies>
        <proxy>
            <active>true</active>
            <protocol>http</protocol>
            <host>10.10.204.160</host>
            <port>80</port>
        </proxy>
    </proxies>
-->
</settings>
© 著作权归作者所有

Maven配置 settings.xml 转的更多相关文章

  1. maven配置settings.xml【阿里云】

    <?xml version="1.0" encoding="utf-8"?> <settings xmlns="http://mav ...

  2. Maven的settings.xml配置详解

    子节点详细介绍转载:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension 全局配置 ...

  3. Maven中settings.xml文件各标签含义

    原文地址:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension settings.x ...

  4. Maven的settings.xml文件结构之mirrors

    Maven的远程库提供大量构件,供Maven项目直接下载使用.对于一个Maven项目,如果没有特别声明,默认使用Maven的central库,url如下: http://repo.maven.apac ...

  5. 详解Maven用户的配置settings.xml

    Maven用户设置 作者其他技术文章 1)Oracle性能优化之查询语句通用原则 2)Redis常用命令 3) SpringCloud入门之常用的配置文件 application.yml和 boots ...

  6. Maven 的 settings.xml 配置中的mirror节点

    maven2的setting.xml大家都知道,里面有个mirrors节点,用来配置镜像URL. mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性 ...

  7. Maven项目settings.xml的配置

    原文地址 http://www.cnblogs.com/DreamDrive/p/5571916.html 在Maven中提供了一个settings.xml文件来定义Maven的全局环境信息.这个文件 ...

  8. [No000016B]清华maven库配置settings.xml

    路径:"C:\Users\%USERNAME%\.m2\settings.xml" <settings xmlns="http://maven.apache.org ...

  9. maven的settings.xml详细说明

    转自:http://writeblog.csdn.net/ <?xml version="1.0" encoding="UTF-8"?> <s ...

随机推荐

  1. c++ explicit 用法摘抄

    笔记 //Student.h[explicit修饰] Student (int n): Student doh(); doh = ; //没有 explicit=>doh = Student(5 ...

  2. js在本地预览图片

    移动web <body> <form enctype="multipart/form-data" name="form1"> 上传文件: ...

  3. CentOS 6.4 播放avi格式的视频文件

    1. 需要先进行相关的yum源的导入: rpm -Uhv http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0. ...

  4. centos nginx

    1.关闭SELinux 查看SELinux状态: (1)/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: ...

  5. aspose.cells根据模板导出excel

    又隔十多天没写博客了,最近都在忙项目的事情,公司人事变动也比较大,手头上就又多了一个项目.最近做用aspose.cells根据模板导出excel报价单的功能,顺便把相关的核心记下来,先上模板和导出的效 ...

  6. Excel Skill (1) -- 判断时如何去掉框里的空格

    使用命令 TRIM 说明: Purpose. Remove extra spaces from text. Text with extra spaces removed. =TRIM (text) t ...

  7. tomcat https 配置

    以前基本上笔者对于安全性考虑的并不多,最近因为saas平台要开始逐渐推广,所以需要开始逐渐加强xss/crsf/https等措施以避免潜在的安全性风险.本文简单的记录下tomcat下https的配置. ...

  8. adb logcat 查看日志

    使用 logcat 命令 查看和跟踪系统日志缓冲区的命令logcat的一般用法是: [adb] logcat [<option>] ... [<filter-spec>] .. ...

  9. Java多线程初学者指南(11):使用Synchronized块同步方法

    synchronized关键字有两种用法.第一种就是在<使用Synchronized关键字同步类方法>一文中所介绍的直接用在方法的定义中.另外一种就是synchronized块.我们不仅可 ...

  10. [原博客] POI系列(1)

    正规.严谨.精妙. -POI 发现POI(波兰信息学奥赛)的题都很有意思.于是开刷bzoj上的poi题目(按ac人数降序..).顺手写一写题解,加深印象. 为了防止一篇文章过于长,打算每五道题另起一篇 ...