Running jacocoReport

2019-02-21 10:07发布

问题:

I'm using gradle 1.7 and jacoco plugin. My project uses java and scala plugins

When I run gradlew -i clean jacocoTestReport

Report is not created and I see in the log

:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main] - start
:bl:jacocoTestReport
Skipping task ':bl:jacocoTestReport' as task onlyIf is false.
:bl:jacocoTestReport SKIPPED
:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main]) - complete

What does it mean? Why report is not created?

回答1:

The task will only run if coverage data is available. You can make sure of that by also running the test task.



回答2:

Add the following at a top level to your build.gradle:

test {
 finalizedBy jacocoTestReport
}

This means that at the end of the test task the jacocoTestReport task should be run. You will receive your coverage analysis after run the tests.



回答3:

None of the above worked for me. What worked for me was the following

Add to the top of my build.gradle:

apply plugin: 'jacoco' // code coverage reports

Add the following as a 'task':

// Generate code coverage reports ... run with jacoco
jacocoTestReport{
    additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/reports/jacoco/html"
    }
    executionData = files('build/jacoco/test.exec')
}

Add the following to your gradle test task:

finalizedBy jacocoTestReport

Then I issued the following command:

gradle run test jacoco