reportOn replacement for gradle 8

This old post was helpful:

However, reportOn is deprecated, and the replacement is not clear.

This is a snippet of my top-level build.gradle:

task allTestsReport(type: TestReport) {
  destinationDirectory = file("$buildDir/reports/allTests")
  reportOn subprojects*.test
  doFirst {
    println "Consolidating tests in $buildDir/reports/allTests"
    project.file("$buildDir/reports/allTests").mkdirs()
  }
}

At build time under gradle 7.4, I get:

The TestReport.reportOn(Object…) method has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the testResults method instead. See TestReport - Gradle DSL Version 7.4 for more details.

The documentation is not clear though. I can’t just swap reportOn out for testResults, and there seems to be more involved given the section the error links to.

What should change to be prepared for gradle 8?

1 Like

The DSL it links to and also the JavaDoc are pretty clear, aren’t they?
They say

use TestReport.getTestResults() and invoke ConfigurableFileCollection.from(java.lang.Object[]) instead, passing references to AbstractTestTask.getBinaryResultsDirectory() as arguments.

So basically it should be something like

testResults.from(subprojects*.test*.binaryResultsDirectory

But actually you might be interested in simply using the Test Report Aggregation Plugin:
https://docs.gradle.org/7.4/release-notes.html#aggregation-tests
https://docs.gradle.org/7.4/userguide/test_report_aggregation_plugin.html

1 Like

In Gradle 8.5, I’ve removed the following snippet from my parent build.gradle:

task testReport(type: TestReport) {
    destinationDir = file("./reports/allTests")
    // Include the results from the `test` task in all subprojects
    reportOn subprojects*.test
}

and created a separate subproject, say test-results, with the following build.gradle:

plugins {
     id 'base'
     id 'test-report-aggregation'
}

dependencies {
     testReportAggregation project(':subprojectA')
     testReportAggregation project(':subprojectB')
     testReportAggregation project(':subprojectN')
}

reporting.baseDir = "../reports/allTests"

test.finalizedBy('testAggregateTestReport')

run.enabled = false