-
本地仓库
-
存储在本地磁盘中,从远程仓库下载的依赖,都存放在此;
-
在 maven的settings.xml中配置<localRepository>,默认路径“.m2/repository”;
-
项目的运行会根据配置pom.xml加载本地仓库依赖
-
-
远程仓库
-
存储在网络上,本地仓库找不到的依赖,会从远程仓库加载;
-
可以在maven的settings.xml中配置<profiles>,或项目的pom.xml文件中指定<repositories>
-
-
中央仓库
-
Maven团队维护的远程仓库,包含了世界上大部分流行的开源项目的构件。
-
中央仓库提供了大量常用依赖项和插件,是Maven默认的下载源。
-
用户无需特别配置,Maven会默认连接中央仓库获取依赖。
-
-
私服仓库
-
一种特殊的远程仓库,通常有公司内部维护
-
注意远程仓库包含,中央仓库、私服仓库、和其他仓库,也就是说,对于maven 使用者来说,远程仓库配置为中央仓库、私服仓库或其他公共仓库都可以。
Maven加载顺序:
-
本地仓库,项目运行,会根据pom.xml依赖,去maven配置的本地仓库地址,加载所需要的依赖
-
远程仓库,如果本地仓库没有找到,会根据maven配置的远程仓库,从远程仓库下载对应依赖到本地仓库
-
如果还没有找到,maven会去中央仓库加载
Maven远程仓库,有三种方式
-
settings.xml中<mirrors>
-
settings.xml中<profiles>
-
pom.xml中<repositories>
正常使用第一种方式,配置 <mirrors> 镜像地址即可,下面知识了解,无需甚解 。如果项目中遇到,知道是配置远程仓库地址即可,项目一般很少用到
mirrors是全局的,会拦截所有仓库请求,优先级最高
profiles是条件性的,里面包含repositories标签,只有激活才会生效,且优先级低于mirrors
sttings.xml
<profiles>
<profile>
<id>custom-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>custom-repo</id>
<name>Custom Repository</name>
<url>http://your.remote.repo/url</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
pom.xml
<repositories>
<repository>
<id>custom-repo</id>
<name>Custom Repository</name>
<url>http://your.remote.repo/url</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

被折叠的 条评论
为什么被折叠?



