Maven报错‘must be pom but is jar’及父POM循环依赖求助
Maven构建错误分析与解决
问题现象
运行Maven构建时,pom.xml第6行<groupId>org.springframework.boot</groupId>处触发报错,完整错误日志如下:
[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Invalid packaging for parent POM com.example:chatpage:0.0.1-SNAPSHOT, must be "pom" but is "jar" @ com.example:chatpage:0.0.1-SNAPSHOT [ERROR] Invalid packaging for parent POM com.example:chatpage:0.0.1-SNAPSHOT, must be "pom" but is "jar" @ org.springframework.boot:spring-boot-starter-parent:3.2.5 [FATAL] The parents form a cycle: com.example:mynewfiledemo1:0.0.1-SNAPSHOT -> org.springframework.boot:spring-boot-dependencies:3.2.5 -> org.springframework.boot:spring-boot-starter-parent:3.2.5 -> org.springframework.boot:spring-boot-dependencies:3.2.5 @ org.springframework.boot:spring-boot-starter-parent:3.2.5 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.example:mynewfiledemo1:0.0.1-SNAPSHOT (C:\Users\Bhagyashree Meena\Downloads\chatdemo\pom.xml) has 3 errors [ERROR] Invalid packaging for parent POM com.example:chatpage:0.0.1-SNAPSHOT, must be "pom" but is "jar" @ com.example:chatpage:0.0.1-SNAPSHOT [ERROR] Invalid packaging for parent POM com.example:chatpage:0.0.1-SNAPSHOT, must be "pom" but is "jar" @ org.springframework.boot:spring-boot-starter-parent:3.2.5 [ERROR] The parents form a cycle: com.example:mynewfiledemo1:0.0.1-SNAPSHOT -> org.springframework.boot:spring-boot-dependencies:3.2.5 -> org.springframework.boot:spring-boot-starter-parent:3.2.5 -> org.springframework.boot:spring-boot-dependencies:3.2.5 @ org.springframework.boot:spring-boot-starter-parent:3.2.5 [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
当前使用的pom.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 https://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.2.5</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>mynewfiledemo1</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mynewfiledemo1</name> <description>Demo project for Spring Boot</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
错误原因
- 本地仓库存在非法父POM:日志反复提示
com.example:chatpage:0.0.1-SNAPSHOT打包类型错误——父POM必须使用pom打包,但该POM被标记为jar,导致Maven解析失败。 - Spring Boot父POM缓存损坏:出现
spring-boot-dependencies与spring-boot-starter-parent互相引用的循环依赖,这是本地Maven仓库缓存文件损坏的典型表现。和Spring Initializr无关,你提供的pom.xml是标准的Spring Boot初始化结构,没有配置问题。
解决步骤
- 清理本地Maven仓库异常缓存:
- 找到本地Maven仓库路径(Windows默认是
C:\Users\你的用户名\.m2\repository,Linux/macOS默认是~/.m2/repository) - 删除以下目录:
com/example/chatpageorg/springframework/boot/spring-boot-starter-parentorg/springframework/boot/spring-boot-dependencies
- 找到本地Maven仓库路径(Windows默认是
- 重新执行构建:运行
mvn clean install,Maven会自动从远程仓库下载正确的父POM文件。 - 检查本地项目(可选):如果本地存在
chatpage项目,确保它的pom.xml中<packaging>设置为pom(若作为父项目),避免再次污染仓库缓存。
内容的提问来源于stack exchange,提问作者Twinkle Jangir
相关产品推荐
相关产品推荐

