Maven 国内高速镜像推荐(按速度排序)
一、主流镜像源对比
| 镜像源 | 地址 | 同步频率 | 平均响应 | 推荐指数 | 备注 |
|---|---|---|---|---|---|
| 阿里云(首选) | https://maven.aliyun.com/repository/public |
每小时 | ~80ms | ⭐⭐⭐⭐⭐ | 全国CDN,不限速,覆盖最全 |
| 华为云 | https://repo.huaweicloud.com/repository/maven/ |
实时增量 | ~90ms | ⭐⭐⭐⭐ | 稳定可靠,适合作为备用 |
| 腾讯云 | https://mirrors.cloud.tencent.com/nexus/repository/maven-public/ |
每日 | ~110ms | ⭐⭐⭐⭐ | 南方节点速度较快 |
| 中科大 USTC | https://mirrors.ustc.edu.cn/maven-central/ |
每2小时 | ~120ms | ⭐⭐⭐ | 高校镜像,教育网优势 |
结论:阿里云综合速度最快、覆盖最广、同步最及时,是国内开发者的首选。实测 Spring Boot 项目首次构建可从 8 分钟压缩至 1 分钟左右。
二、最快配置方案(阿里云镜像)
配置文件位置
- 用户级(推荐) :
~/.m2/settings.xml(Windows:C:\Users\用户名\.m2\settings.xml) - 全局级 :
Maven安装目录/conf/settings.xml
如果没有 settings.xml,从 Maven 安装目录的 conf 文件夹复制一份到 .m2 目录下即可。
最简配置(只代理中央仓库)
xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0
https://maven.apache.org/xsd/settings-1.2.0.xsd">
<mirrors>
<!-- 阿里云公共仓库 - 首选 -->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
</settings>
全能配置(拦截所有仓库请求,推荐)
使用 <mirrorOf>*</mirrorOf> 拦截所有仓库请求,全部走阿里云,速度最大化:
xml
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
注意 :
<mirrorOf>*</mirrorOf>会代理所有仓库。如果有公司内部私服,使用<mirrorOf>external:*</mirrorOf>排除内网仓库。
三、双镜像容错配置(主备切换)
阿里云 + 华为云双保险,一个故障自动切另一个(按顺序匹配):
xml
<mirrors>
<!-- 主:阿里云 -->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<!-- 备:华为云 -->
<mirror>
<id>huaweicloud</id>
<mirrorOf>central</mirrorOf>
<name>华为云公共仓库</name>
<url>https://repo.huaweicloud.com/repository/maven/</url>
</mirror>
</mirrors>
四、额外提速优化
-
开启并行下载(Maven 3.9+)
bashmvn clean install -T 1C # 每个CPU核心一个线程 -
跳过校验加快速度
xml<releases> <checksumPolicy>ignore</checksumPolicy> </releases> -
调整本地仓库路径到SSD盘,IO速度提升明显
-
验证配置生效
bashmvn help:effective-settings查看输出中 mirror 地址是否为阿里云。
五、阿里云专项仓库(按需添加)
阿里云还提供了多个专项仓库,可根据项目需要在 pom.xml 中单独配置:
| 仓库类型 | 地址 |
|---|---|
https://maven.aliyun.com/repository/google |
|
| Spring | https://maven.aliyun.com/repository/spring |
| JCenter | https://maven.aliyun.com/repository/jcenter |
| Apache Snapshots | https://maven.aliyun.com/repository/apache-snapshots |