How do I run generate all jacoco reports?


(Matt Khan) #1

If you have multiple test tasks then the jacoco plugin will add a report task for each test task. These report tasks are finalised by the buildDashboard task so if they run then the dashboard will be updated. However the report tasks do not finalise the test task so I can see no obvious way to make them run when the tests run.

Is there a simple way to do this? if not, it would be nice if the plugin could be configured to do this automatically


(Peter Niederwieser) #2

I think the idea was to keep test execution and report generation decoupled by default. Can’t you add the necessary dependencies yourself?


(Matt Khan) #3

I can (and am), it just seems like it would be easier to do from the plugin rather than having to go and discover the reports that can be run and then add a task to draw them all together.


(Peter Niederwieser) #4

How would you do this without coupling test execution to report generation for everyone?


(Matt Khan) #5

provide a configuration option on the plugin to let you choose whether to link it or not


(Peter Niederwieser) #6

What exactly would the configuration option do?


(Matt Khan) #7

Add the report task as a finaliser of the task that produces the jacoco.exec


(Peter Niederwieser) #8

If you want to run tests and produce reports, run the report tasks. If you only want to run tests, run the test tasks. How would you like to see this improved? Maybe the design decision stems from not having a way to run tests without recording coverage (once the ‘jacoco’ plugin is applied). So the author at least wanted to provide a way to run tests without generating coverage reports.


(Matt Khan) #9

this is fine when you have a default setup (1 test task per project called test and hence 1 report task jacocoTestReport) but when you have n test tasks and hence n report tasks then there is no simple shortcut to run them all without wiring them together yourself. This becomes important in a CI environment with a variety of projects running the same core build as it lets you minimise the variance in the configuration so I just have a TeamCity template that runs gradlew release jacocoCompleteReport and I get every reports generated in 1 go. This doesn’t seem like an uncommon use case to me.


(Peter Niederwieser) #10

Why isn’t ‘task jacocoCompleteReport(dependsOn: tasks.withType(JacocoReport))’ good enough to achieve this? The report tasks should already be wired to the test tasks, no?