maven:Project build error: Non-resolvable parent POM for model:maven01:0.0.1-SNAPSHOT

本文介绍了解决Maven项目中因无法正确下载依赖而导致的构建错误的方法。通过配置阿里云Maven镜像,可以有效提升依赖包的下载速度,并解决因网络问题导致的构建失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

创建maven项目的时候,添加parent标签,报错误:

Project build error: Non-resolvable parent POM for model:maven01:0.0.1-SNAPSHOT: Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): connect timed out and 'parent.relativePath' points at wrong local POM

解决:

maven使用国内代理————阿里镜像
参考博客:http://www.cnblogs.com/littleatp/p/6002289.html
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<!--<mirrorOf>central</mirrorOf> -->
<mirrorOf>*</mirrorOf>
</mirror>


不可以的尝试这个:

<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>


### 解决方案分析 在 Maven 项目中遇到 `Non-resolvable parent POM` 错误通常是因为父 POM 文件未被正确解析。以下是可能的原因以及解决方案: #### 原因分析 1. **仓库配置错误** 如果本地或远程仓库中不存在指定版本的 Spring Boot Starter Parent,则会引发此问题。例如,Spring Boot 版本 `3.4.4` 可能并不存在于官方 Maven 中央仓库或其他自定义仓库中[^1]。 2. **网络连接问题** 当 Maven 尝试从远程仓库下载依赖项时,如果网络不稳定或者代理设置不正确,可能导致下载失败[^2]。 3. **相对路径配置错误 (`relativePath`)** 在某些情况下,`<parent>` 节点中的 `<relativePath>` 属性可能会指向一个无效的位置,从而导致无法找到对应的 POM 文件[^3]。 4. **缓存问题** Maven 的本地缓存机制有时会出现问题,特别是当某个依赖项曾经尝试下载但失败后,会被标记为不可用状态,直到强制刷新才会重新尝试下载[^4]。 --- ### 解决方法 #### 方法一:验证 Spring Boot 版本是否存在 确认所使用的 Spring Boot 版本号是否有效。访问 [Maven Central Repository](https://search.maven.org/) 并搜索 `org.springframework.boot:spring-boot-starter-parent` 来核实是否有 `3.4.4` 这个版本。如果没有该版本,可以选择最近的一个稳定版替代它。 ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.0</version> <!-- 替换为你需要的有效版本 --> </parent> ``` #### 方法二:检查仓库地址 确保项目的 `pom.xml` 或全局 `settings.xml` 配置文件中包含了正确的仓库地址。默认情况下,应该包含 Maven 中央仓库: ```xml <repositories> <repository> <id>central</id> <url>http://repo.maven.apache.org/maven2</url> </repository> </repositories> ``` 如果有其他私有仓库,请确保其 URL 和认证信息无误。 #### 方法三:清除本地缓存 执行以下命令清理本地 Maven 缓存,并强制更新依赖项: ```bash mvn clean install -U ``` 参数 `-U` 表示强制更新快照和发布版本。 #### 方法四:调整 `relativePath` 如果项目中有多个模块共享同一个父 POM,可以显式指定 `relativePath` 的位置。例如: ```xml <parent> <groupId>com.example</groupId> <artifactId>example-parent</artifactId> <version>1.0-SNAPSHOT</version> <relativePath>../example-parent/pom.xml</relativePath> </parent> ``` 如果不希望使用相对路径,可以直接移除 `<relativePath>` 属性,默认值为空字符串表示查找当前目录下的 POM 文件。 #### 方法五:降级到已知稳定的版本 如果上述方法均未能解决问题,考虑将 Spring Boot 版本回退至更早的稳定版本(如 `2.7.x`),以排除潜在兼容性问题。 ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.9</version> </parent> ``` --- ### 示例代码片段 以下是一个完整的 `pom.xml` 配置模板供参考: ```xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.0</version> <!-- 确认可用版本 --> </parent> <groupId>com.example</groupId> <artifactId>demo-project</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` --- ###
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伍六七AI编程

你猜你给我1分我要不要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值