阿里云 Maven 镜像配置实战
在国内做 Java 开发,最头疼的莫过于依赖下载慢。每次跑个 mvn build 都要等半天,有时候还直接超时。其实只要把 Maven 的镜像源换成阿里云的,这个问题基本就解决了。
为什么推荐阿里云镜像?
官方 Central 仓库在国内访问确实不稳定。阿里云提供的镜像不仅速度快,而且同步及时,覆盖了 public、google 等常用仓库。对于大多数项目来说,这是性价比最高的方案。
动手配置 settings.xml
先找到你的 Maven 配置文件。通常在 $MAVEN_HOME/conf/settings.xml 或者 ~/.m2/settings.xml。打开它,在 <mirrors> 标签里插入下面的内容。
<mirrors>
<!-- 阿里云公共仓库 -->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<!-- 阿里云 Google 仓库 -->
<mirror>
<id>aliyun-google</id>
<mirrorOf>google</mirrorOf>
<name>阿里云 Google 仓库</name>
<url>https://maven.aliyun.com/repository/google</url>
</mirror>

