Maven的国外镜像仓库访问不稳定,安装完MAVEN后一般都需要配置国内镜像地址。
1. 配置文件修改
- 修改Maven全局配置文件,aliyun仓库镜像配置如下:
<!-- 阿里云中央仓库 159行 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
- 修改项目 pom.xml 配置文件,加上 repositories 和 pluginRepositories
<repositories>
<repository>
<id>central</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
2. 说明
-
mirror
mirror就是镜像,主要提供一个方便地切换远程仓库地址的途径。 -
mirror.mirrorOf
central 里是要替代的仓库的id,如果填*,就会替代所有仓库。