Using Gradle 5.4.1 (and now 5.5.1), I was able to get a report after any test task, currently I have test and integrationTest tasks.
EDIT2 : the solution is the same, I just tweaked
- assigning reports to use
jacoco.reportsDir , - now
tasks.withType(Test) used for executeData, and not just [test, integrationTest] executionData is configured in the doFirst block instead of doLast
EDIT : After viewing the JacocoReport documentation, there is a variant of JacocoReport: executeData that directly accepts Gradle tasks. This works because the JaCoCo plugin adds the JacocoTaskExtension extension to all tasks like Test . Which is then less error prone. The task of the report is:
jacocoTestReport { doFirst { // The JaCoCo plugin adds a JacocoTaskExtension extension to all tasks of type Test. // Use task state to include or not task execution data // https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskState.html executionData(tasks.withType(Test).findAll { it.state.executed }) } reports { xml.enabled true xml.destination(file("${jacoco.reportsDir}/all-tests/jacocoAllTestReport.xml")) html.enabled true html.destination(file("${jacoco.reportsDir}/all-tests/html")) } }
And the same trick can be applied to the sonarqube task:
sonarqube { group = "verification" properties { // https://jira.sonarsource.com/browse/MMF-1651 property "sonar.coverage.jacoco.xmlReportPaths", jacocoTestReport.reports.xml.destination properties["sonar.junit.reportPaths"] += integrationTest.reports.junitXml.destination properties["sonar.tests"] += sourceSets.integrationTest.allSource.srcDirs // ... other properties } }
Old but very working answer. Also, using the above information (that the Test task has been extended by JacocoTaskExtension ), you can replace the manual configuration of file executionData with test.jacoco.destinationFile and integrationTest.jacoco.destinationFile .
// Without it, the only data is the binary data, // but I need the XML and HTML report after any test task tasks.withType(Test) { finalizedBy jacocoTestReport } // Configure the report to look for executionData generated during the test and integrationTest task jacocoTestReport { executionData(file("${project.buildDir}/jacoco/test.exec"), file("${project.buildDir}/jacoco/integrationTest.exec")) reports { // for sonarqube xml.enabled true xml.destination(file("${project.buildDir}/reports/jacoco/all-tests/jacocoAllTestReport.xml")) // for devs html.enabled true html.destination file("${project.buildDir}/reports/jacoco/all-tests/html") } } sonarqube { group = "verification" properties { // https://jira.sonarsource.com/browse/MMF-1651 property "sonar.coverage.jacoco.xmlReportPaths", ${project.buildDir}/test-results/integrationTest" properties["sonar.junit.reportPaths"] += "${project.buildDir}/test-results/integrationTest" properties["sonar.tests"] += sourceSets.integrationTest.allSource.srcDirs // ... other properties } } project.tasks["sonarqube"].dependsOn "jacocoTestReport"
source share