Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a replacement for a deprecated JaCoCo extension in Gradle?

I'm using Robolectric and JaCoCo together. My code coverage reports do not work without the following lines of code in gradle script:

 testOptions {
    unitTests.all {
        jacoco {
            includeNoLocationClasses = true
        }
    }
 }

But in the recent version of Gradle the JaCoCo extension, that I use here, is marked as deprecated. I could not find any replacement for it. So, where should I apply the includeNoLocationClasses = true option?

like image 604
Lingviston Avatar asked Jan 10 '18 08:01

Lingviston


People also ask

What is jacocoTestReport?

JaCoCo Report configurationThe JacocoReport task can be used to generate code coverage reports in different formats. It implements the standard Gradle type Reporting and exposes a report container of type JacocoReportsContainer.


2 Answers

Using the Gradle Kotlin DSL with Gradle 5.5.1 and Kotlin 1.3.31 this works:

tasks {
    withType<Test> {
        configure<JacocoTaskExtension> {
            isIncludeNoLocationClasses = true
        }
    }
}
like image 183
Tom Hanley Avatar answered Oct 23 '22 09:10

Tom Hanley


I found a solution. JaCoCo automatically adds jacoco extension to all tasks of test type. So, all that I had to do was adding the following lines into build script:

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
}

It doesn't look like an official solution, but it allows the custom JacocoReport implementation to work correctly.

like image 23
Lingviston Avatar answered Oct 23 '22 09:10

Lingviston