1

我已经为几个 gradle 项目配置了 jacoco 覆盖率插件,但是在运行 jacocoTestReport 任务时出现错误。

我曾尝试将 jacoco 依赖项添加为 testRuntime 或编译,但它根本没有帮助。

我也尝试添加代理 jar,但没有成功。

jacocoTestReport {
    File jacocoLibDir = file("$buildDir/tmp/expandedArchives/org.jacoco.agent-0.8.5")
    jacocoClasspath = files { jacocoLibDir.listFiles() }
}

我得到的错误是:

> Task :jacocoTestReport FAILED

Execution failed for task ':jacocoTestReport'.
> org/jacoco/core/analysis/ICoverageVisitor

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jacocoTestReport'.
    ...
Caused by: java.lang.NoClassDefFoundError: org/jacoco/core/analysis/ICoverageVisitor
    ... 
Caused by: java.lang.ClassNotFoundException: org.jacoco.core.analysis.ICoverageVisitor
    ... 64 more
4

1 回答 1

1

在 build.gradle 中添加以下部分使任务执行成为可能

buildscript {
    dependencies {
        classpath("org.jacoco:org.jacoco.ant:0.8.5")
    }
}

jacocoTestReport {
    jacocoClasspath = project.buildscript.configurations.classpath
}
于 2020-08-21T08:21:33.163 回答