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

IntelliJ配置Jacoco时,代码覆盖率无指定替代运行器选项

解决IntelliJ中Jacoco覆盖率运行器选项缺失的问题
  • 检查插件状态与IDE版本适配

    1. 打开File > Settings > Plugins,搜索JaCoCo,确认插件已启用,未启用则点击启用并重启IDE。
    2. 若使用IntelliJ 2023.3及以后版本,配置逻辑已调整:无需在Run Config中选择运行器,直接通过覆盖率报告界面切换工具。
  • 新版本IntelliJ配置Jacoco步骤

    1. 先给项目添加Jacoco依赖:
      • Maven项目在pom.xml中加入插件配置:
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.12</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        
      • Gradle项目在build.gradle中加入:
        plugins {
            id 'jacoco'
        }
        
        jacocoTestReport {
            reports {
                xml.required = true
                html.required = true
            }
        }
        
    2. 生成并切换覆盖率工具:
      • 右键测试类/模块,选择Run 'xxx' with Coverage
      • 测试完成后,在弹出的覆盖率窗口右上角,点击选择覆盖率运行器的下拉按钮,选中JaCoCo即可。
  • 旧版本IntelliJ(2023.2及更早)配置方式

    1. 打开Run > Edit Configurations,选中你的目标运行配置(如JUnit/Application)
    2. 切换到Coverage标签页,勾选Enable coverage
    3. 点击Choose coverage runner下拉框,选择JaCoCo,若仍无选项,重启IDE再试。

若以上操作无效,尝试清理缓存重启:File > Invalidate Caches... > 勾选Clear file system cache and local history > 点击Invalidate and Restart

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 01:30:01