maven的setting使用
1
<mirrors>
2 <!--国内阿里云提供的镜像,非常不错-->
3 <mirror>
4 <!--This sends everything else to /public -->
5 <id>aliyun_nexus</id>
6 <!--对所有仓库使用该镜像,除了一个名为maven_nexus_201的仓库除外-->
7 <!--这个名为2441940-release-Kg0bES的仓库可以在javamaven项目中配置一个repository-->
8 <mirrorOf>*,!2441940-release-Kg0bES</mirrorOf>
9 <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
10 </mirror>
11 </mirrors>
id 镜像的唯一标识
mirrorOf 代表了一个镜像的替代位置,例如central就表示代替官方的中央库
* 匹配所有,所有内容都从镜像拉取
central 替代Maven中央仓库。
external:* 除了本地缓存的所有从镜像仓库拉取
repo,repo1 repo 或者 repo1 ,这里的 repo 指的仓库 ID
*,!repo1 除了 repo1 的所有仓库
name 名称描述
url 地址
<mirrorOf></mirrorOf>的设置很重要,比如上面我设置的mirrorOf为<mirrorOf>central</mirrorOf>,如果<mirrorOf>
</mirrorOf>我随便设置一个参数,如<mirrorOf>abc</mirrorOf>,这时候我们配置的仓库就不起作用了,这是因为
maven默认内置了如下一个仓库,这个默认仓库的id为central,当我们把mirrorOf设置为<mirrorOf>central</mirrorOf>
时,maven就会查找有没有id为central的仓库,然后把id为central的仓库地址换成我们<mirror>标签配置的那个url,这
样我们配置的mirror才会起作用。当然我们也可以把mirrorOf设置为<mirrorOf>*</mirrorOf>,表示所有仓库都使用我们
配置的这个mirror作为jar包下载地址。
虽然mirrors可以配置多个子节点,但是它只会使用其中的一个节点,即默认情况下配置多个mirror的情况下,只有第一
个生效,只有当前一个mirror
无法连接的时候,才会去找后一个;而我们想要的效果是:当a.jar在第一个mirror中不存在的时候,maven会去第二个
mirror中查询下载,但是maven不会这样做!
远程仓库
1
<profiles>
2 <profile>
3 <id>rdc</id>
4 <properties>
5 <altReleaseDeploymentRepository>
6 2441940-release-
Kg0bES::default::https://packages.aliyun.com/maven/repository/2441940-release-Kg0bES
7 </altReleaseDeploymentRepository>
8 </properties>
9 <repositories>
10 <repository>
11 <id>2441940-release-Kg0bES</id>
12 <url>https://packages.aliyun.com/maven/repository/2441940-release-Kg0bES</url>
13 <releases>
14 <enabled>true</enabled>
15 </releases>
16 <snapshots>
17 <enabled>true</enabled>
18 </snapshots>
19 </repository>
20
21 <repository>
22 <id>2441940-snapshot-kHZslB</id>
23 <url>https://packages.aliyun.com/maven/repository/2441940-snapshot-kHZslB</url>
24 <releases>
25 <enabled>true</enabled>
26 </releases>
27 <snapshots>
28 <enabled>true</enabled>
29 </snapshots>
30 </repository>
31 </repositories>
32 </profile>
33 </profiles>
34
35 <activeProfiles>
36 <activeProfile>rdc</activeProfile>
37 </activeProfiles>
repository 配置多个会从上到下一次匹配
mirrors 与profiles 设置repository的区别
mirror 与 repository 不同的是,假如配置同一个 repository 多个 mirror 时,相互之间是备份
关系,只有当仓库连不上时才会切换到另
一个,而如果能连上但是找不到依赖时是不会尝试下一个 mirror 地址的
当远程仓库被镜像匹配到的,则在获取 jar 包将从镜像仓库获取,而不是我们配置的 repository 仓库,
repository 将失去作用