作为一名Java开发者,Maven是我们日常开发中不可或缺的构建工具。然而曾经遇到过以下问题:

  • 依赖下载速度极慢,每次构建项目都要等待很长时间

  • 配置了多个镜像,却发现某些依赖仍然下载失败

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<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">

<!-- 本地仓库的位置 -->
<localRepository>C:\IDEA\my-idea-repository</localRepository>

<!-- 镜像设置 -->
<mirrors>
<!-- 中央仓库镜像 -->
<mirror>
<id>aliyun-central</id>
<mirrorOf>central</mirrorOf>
<name>阿里云中央仓库镜像</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>

<!-- 谷歌仓库镜像 -->
<mirror>
<id>aliyun-google</id>
<mirrorOf>google,com.google.android</mirrorOf>
<name>阿里云谷歌仓库</name>
<url>https://maven.aliyun.com/repository/google</url>
</mirror>

<!-- Spring 相关仓库镜像 -->
<mirror>
<id>aliyun-spring</id>
<mirrorOf>spring-milestone,spring-snapshot</mirrorOf>
<name>阿里云Spring仓库</name>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>

<!-- 备用中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Maven Central Repository 1</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
</mirrors>

<!-- 自定义仓库配置 -->
<profiles>
<profile>
<id>aliyun-repos</id>
<repositories>
<!-- 中央仓库 -->
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>

<!-- 阿里云公共仓库(非镜像模式) -->
<repository>
<id>aliyun-public</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!-- 激活配置 -->
<activeProfiles>
<activeProfile>aliyun-repos</activeProfile>
</activeProfiles>

</settings>