Naan
Naan

Reputation: 541

NoClassDefFoundError when running jacocoTestReport gradle task

I have configured jacoco coverage plugin for few gradle projects, but with one I get error when running jacocoTestReport task.

I have tried adding jacoco dependencies as testRuntime or compile, but it didn't help at all.

I also tried adding agent jar, with no success.

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

The error I am getting is:

> 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

Upvotes: 1

Views: 4000

Answers (1)

Naan
Naan

Reputation: 541

Adding following parts in build.gradle made task executions possible

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

jacocoTestReport {
    jacocoClasspath = project.buildscript.configurations.classpath
}

Upvotes: 1

Related Questions