BUGFIX 【修复SpringAI导入maven报错】
1. 问题概述
版本
- idea 2025.1.1.1
- maven 3.9.6
- spring AI 0.8.1
报错截图
Non-resolvable import POM: The following artifacts could not be resolved: org.springframework.ai:spring-ai-bom:pom:0.8.1 (absent): org.springframework.ai:spring-ai-bom:pom:0.8.1 failed to transfer from https://repo.spring.io/milestone during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of spring-milestones has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.ai:spring-ai-bom:pom:0.8.1 from/to spring-milestones (https://repo.spring.io/milestone): repo.spring.io
2. 复现
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-ai.version>0.8.1</spring-ai.version>
</properties>
问题原因分析
- Maven 将下载失败的状态缓存了,因此不会重新尝试,除非强制刷新或等待缓存超时
- 阿里云 Maven 镜像 并未托管该版本或该组件
3. 修复方案
强制刷新maven缓存
mvn clean install -U
- -U 参数会强制更新所有 SNAPSHOT 和 RELEASE 依赖。
确认是否真实存在
阿里云仓库文档: https://developer.aliyun.com/mvn/guide
应该爬的maven的仓库
搜索maven的仓库:https://search.maven.org/search?q=spring-ai-bom
没有0.8.1版本
故修改1.0.0.M6
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-ai.version>1.0.0-M6</spring-ai.version>
</properties>
刷新maven, 成功无报错
总结
阿里云 Maven 镜像虽然在国内速度快,但存在同步不完整问题,特别是 Spring Boot、Spring AI、Spring Cloud 的较新版本经常无法及时同步。
在重要项目中,建议保留官方 Maven 仓库或用私服(如 Nexus)中转。