Maven常用仓库及配置多仓库

常用repo列表

首先介绍一个搜索jar包的常用网址:http://mvnrepository.com/

如果想知道哪些库比较流行,可以在 https://mvnrepository.com/repos/central 看到。截止2021年9月,最流行的仍然是central这个库。

center

repo配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
<repository>
<id>central</id>
<!-- This should be at top, it makes maven try the central repo
first and then others and hence faster dep resolution -->
<name>Maven Repository</name>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

jcenter

repo配置:

1
2
3
4
5
6
7
8
9
10
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>

spring plugins

url:https://repo.spring.io/plugins-release/

sonartype

排名靠前。大名鼎鼎的nexus就是sonartype公司的产品。

url:https://oss.sonatype.org/content/repositories/releases/

spring的几个仓库

repo配置:

1
2
3
4
5
6
7
8
<repository>
<id>libs-milestone</id>
<url>https://repo.spring.io/libs-milestone/</url>
</repository>
<repository>
<id>libs-release</id>
<url>https://repo.spring.io/libs-release/</url>
</repository>

aliyun的仓库

aliyun的仓库搭配上面几个库一起使用,就比较全面了,不大会出现找不到jar的问题。可以把aliyun的放到最前面,如果aliyun有就不会找后面的仓库,如果没有再去其他仓库找,这样可以保证速度最快。

repo配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<repository>
<snapshots />
<id>central</id>
<name>ali-central</name>
<url>https://maven.aliyun.com/repository/central</url>
</repository>
<repository>
<id>alispringplugin</id>
<name>spring-plugin</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

maven配置多仓库

经过上面的介绍,相信大家对于应该配置哪些仓库基本有所了解了。当然很多都是经验之谈,基于仓库的流行程度和速度快慢来选择的,没有详细介绍为什么要配置这些仓库,可能在遇到一些特殊的依赖包的时候,恰巧在上述仓库中都没有。那么你就需要把那个包的仓库的配置加到全局的settings.xml中了。

完整的settingx.xml配置如下,可以复制替代你原来默认的配置了(建议原来的备份一份):

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<!-- 这个地方一般用于记录私服的用户密码之类信息,公库一般不需要这个配置-->
<server>
<id>central</id>
</server>
</servers>
<profiles>
<profile>
<id>search-aliyun-first</id>
<repositories>
<!-- aliyun repo-->
<repository>
<snapshots />
<id>central</id>
<name>ali-central</name>
<url>https://maven.aliyun.com/repository/central</url>
</repository>
<repository>
<id>alispringplugin</id>
<name>spring-plugin</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

<!-- maven central-->
<repository>
<id>central</id>
<!-- This should be at top, it makes maven try the central repo
first and then others and hence faster dep resolution -->
<name>Maven Repository</name>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

<!-- jcenter repo-->
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>

<!-- spring repo-->
<repository>
<id>libs-milestone</id>
<url>https://repo.spring.io/libs-milestone/</url>
</repository>
<repository>
<id>libs-release</id>
<url>https://repo.spring.io/libs-release/</url>
</repository>

<!-- sonartype -->
<repository>
<id>sonartype-release</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<snapshots />
<id>aliyun-releases</id>
<name>releases</name>
<url>https://maven.aliyun.com/repository/releases</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>spring-plugins-releases</id>
<name>releases</name>
<url>https://repo.spring.io/plugins-release</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>search-aliyun-first</activeProfile>
</activeProfiles>
</settings>

因为这些配置很难记住,所以记录了一下。希望有所帮助。

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2021 Johnny Li
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信