试了两项目发现可以,还有一个在看,也不知道是不是重复依赖太多导致编译不成功。。。
问题场景:
1.公司有内部搭建的nexus(私有maven库), 添加了 mirror 配置
1
2
3
4
5
<mirror>
<id>yougou</id>
<mirrorOf>*</mirrorOf><!-- *代表拦截了所有仓库, 缺点是也包括了默认的中心仓库 -->
<url>http://repo1.maven.org/maven2/</url>
</mirror>
2.有时候要用到的一些jar包可能公司的私库并没有, 我们一般都会使用aliyun的maven库进行加速
所以, 造成了下载一些jar包时会反复修改setting.xml文件, 很麻烦
官网 关于镜像的介绍 https://maven.apache.org/guides/mini/guide-mirror-settings.html
通过官网的举例
1
2
3
4
5
6
7
8
9
10
11
12
Examples:
* = everything
external:* = everything not on the localhost and not file based.
repo,repo1 = repo or repo1
*,!repo1 = everything except repo1
机器翻译:
例子:
* = 一切
外部:* = 不在本地主机上的所有内容,也不是基于文件的。
repo,repo1 = repo或repo1
*,!repo1 = 除repo1之外的所有内容
得到解决方案(只保留了关键的配置)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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">
<mirrors>
<mirror>
<id>yougou</id>
<mirrorOf>*,!aliyun</mirrorOf> <!-- *镜像拦截了所有的仓库, 但 排除了阿里云的仓库 逗号两边不能有空格 从左到右的顺序 -->
<url>http://repo1.maven.org/maven2/</url> <!-- 设置公司私库地址 -->
</mirror>
</mirrors>
<profiles>
<profile>
<id>aliyun_profile</id>
<repositories>
<repository>
<id>aliyun</id> <!-- 添加阿里云的maven仓库 -->
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun_profile</activeProfile> <!-- 让添加的阿里云仓库生效 -->
</activeProfiles>
</settings>
修改完后可以通过命令来检查 setting.xml文件是否有问题
mvn help:effective-settings