当前位置: 首页 > news >正文

Maven 配置阿里云镜像加速

Maven 配置阿里云镜像加速:

完整配置步骤(Windows 系统)

1. 找到 Maven 的 settings.xml 文件
  • 全局配置D:\software\apache-maven-3.9.11\conf\settings.xml
  • 用户配置C:\Users\Admin\.m2\settings.xml(推荐使用此位置)
2. 修改 settings.xml 文件

用文本编辑器打开文件,添加以下配置:

<settings><!-- 本地仓库位置 --><localRepository>C:\Users\Admin\.m2\repository</localRepository><!-- 镜像配置 --><mirrors><!-- 阿里云主镜像 --><mirror><id>aliyunmaven</id><name>阿里云公共仓库</name><url>https://maven.aliyun.com/repository/public</url><mirrorOf>central,jcenter,google,spring,gradle-plugin,grails-core,apache-snapshots</mirrorOf></mirror><!-- 阿里云插件镜像 --><mirror><id>aliyunPlugin</id><name>阿里云插件仓库</name><url>https://maven.aliyun.com/repository/central</url><mirrorOf>plugin</mirrorOf></mirror></mirrors><!-- 可选:配置下载线程数 --><profiles><profile><id>speedup</id><properties><maven.artifact.threads>8</maven.artifact.threads></properties></profile></profiles><activeProfiles><activeProfile>speedup</activeProfile></activeProfiles>
</settings>

3. 验证配置生效

# 清除本地缓存(可选)
mvn dependency:purge-local-repository# 重新构建项目
mvn clean install -U

4. 高级优化配置(可选)

settings.xml 中添加以下配置加速下载:

<settings>...<!-- 并行构建配置 --><build><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.3.1</version><configuration><useDefaultDelimiters>true</useDefaultDelimiters><parallel>true</parallel><threadCount>4</threadCount></configuration></plugin></plugins></pluginManagement></build><!-- 超时设置 --><servers><server><id>aliyunmaven</id><configuration><httpConfiguration><all><connectionTimeout>60000</connectionTimeout><readTimeout>60000</readTimeout></all></httpConfiguration></configuration></server></servers>
</settings>

5. 解决特定仓库问题

如果某些依赖仍从中央仓库下载,在 pom.xml 中强制指定仓库:

<repositories><repository><id>aliyun</id><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository>
</repositories><pluginRepositories><pluginRepository><id>aliyun-plugin</id><url>https://maven.aliyun.com/repository/public</url></pluginRepository>
</pluginRepositories>

6. 命令行覆盖(临时使用)

mvn clean install -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlTimeout=30000 -Dmaven.wagon.http.readTimeout=60000

常见问题解决

1. 下载卡在某个进度
# 跳过测试并禁用校验
mvn clean install -DskipTests -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
2. 特定依赖下载失败

手动下载并安装:

mvn install:install-file -Dfile=path/to/jar -DgroupId=group.id -DartifactId=artifact-id -Dversion=version -Dpackaging=jar
3. 查看依赖树
mvn dependency:tree -Dverbose

阿里云镜像地址参考

仓库类型阿里云镜像地址
中央仓库https://maven.aliyun.com/repository/public
Googlehttps://maven.aliyun.com/repository/google
Springhttps://maven.aliyun.com/repository/spring
Gradle Pluginhttps://maven.aliyun.com/repository/gradle-plugin
Apache Snapshotshttps://maven.aliyun.com/repository/apache-snapshots

通过以上配置,Maven 下载速度通常可提升 5-10 倍。如果仍有问题,建议检查网络连接或尝试使用 VPN 解决国际带宽限制问题。

http://www.dtcms.com/a/307048.html

相关文章:

  • huggingface是什么?2025-07-30
  • Mac 上配置jdk 环境变量
  • 2. Agent与 React流程
  • 【LY88】双系统指南及避坑
  • Python 的 match-case
  • 从映射到共生:元宇宙、物联网与AI的智能融合生态图谱
  • (LeetCode 面试经典 150 题) 141. 环形链表(快慢指针)
  • HPCtoolkit的下载使用
  • Oracle11g数据库迁移达梦8数据库方案
  • Python序列化和反序列化
  • 如何用Docker部署ROS2
  • (C++)C++类和类的方法(基础教程)(与Python类的区别)
  • c++之基础B之sort排序(第三个参数没有)(第二课)
  • Fiddler中文教程 从入门到进阶的网络抓包与接口调试实战指南
  • Python Pandas.merge_asof函数解析与实战教程
  • VUE前端
  • [Agent开发平台] API网关 | 业务领域 | DTO格式 | 分页令牌
  • React 服务端渲染(SSR)详解
  • 使用 cron 配合 Docker 实现定时任务
  • 神经网络的并行计算与加速技术
  • 模型相关类代码回顾理解 | BatchNorm2d\fc.in_features\nn.Linear\torchsummary
  • Haproxy 七层代理深度解析
  • Ubuntu 本地部署和使用 n8n 指南and ai almost anything
  • REST、GraphQL、gRPC、tRPC深度对比
  • Python Day19 时间模块 和 json模块 及例题分析
  • Dify案例2:基于Workflow的小红书笔记AI智能体以及AI绘图过程中遇到的问题
  • USRP捕获手机/路由器数据传输信号波形(上)
  • Vue面试
  • HTML基础P2 | JS基础讲解
  • 《汇编语言:基于X86处理器》第10章 复习题和练习