You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven项目pom.xml报JUnit Jupiter依赖缺失错误求助

解决JUnit Jupiter依赖Missing artifact错误

你的配置存在两个关键问题,导致Maven无法找到对应依赖:

  1. GroupId错误:JUnit Jupiter(JUnit 5)的groupId是org.junit.jupiter,而非org.junit(后者是JUnit 4的groupId)。
  2. 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>

后续修复步骤

  1. 保存修改后的pom.xml。
  2. 执行Maven命令强制刷新依赖:
    mvn clean install -U
    
  3. 若IDE仍报错,刷新Maven项目(IDEA点击右侧Maven面板的刷新按钮;Eclipse右键项目→Maven→Update Project)。
  4. 若本地仓库存在损坏的依赖缓存,删除本地仓库中org/junit和org/junit/jupiter目录,重新执行上述Maven命令拉取依赖。

内容的提问来源于stack exchange,提问作者Coder6421

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 16:55:08