Maven项目pom.xml报JUnit Jupiter依赖缺失错误求助
解决JUnit Jupiter依赖Missing artifact错误
你的配置存在两个关键问题,导致Maven无法找到对应依赖:
- GroupId错误:JUnit Jupiter(JUnit 5)的groupId是
org.junit.jupiter,而非org.junit(后者是JUnit 4的groupId)。 - Artifact类型错误:
junit-jupiter是一个聚合POM模块,本身没有对应的jar包,默认按jar查找自然会失败。
正确的依赖配置方案
方案一:使用聚合POM(一次性引入所有JUnit Jupiter组件)
修改依赖配置为以下内容,明确指定类型为pom:
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.10.1</version> <scope>test</scope> <type>pom</type> </dependency>
方案二:单独引入核心模块(更灵活)
如果只需要核心测试API和运行引擎,可分别引入:
<!-- 编写测试用例的API --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.10.1</version> <scope>test</scope> </dependency> <!-- 运行测试的引擎 --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.10.1</version> <scope>test</scope> </dependency>
后续修复步骤
- 保存修改后的
pom.xml。 - 执行Maven命令强制刷新依赖:
mvn clean install -U - 若IDE仍报错,刷新Maven项目(IDEA点击右侧Maven面板的刷新按钮;Eclipse右键项目→Maven→Update Project)。
- 若本地仓库存在损坏的依赖缓存,删除本地仓库中
org/junit和org/junit/jupiter目录,重新执行上述Maven命令拉取依赖。
内容的提问来源于stack exchange,提问作者Coder6421
相关产品推荐
相关产品推荐

