I’ve tried a couple different ways to get an aggregate report of FindBugs (or PMD) reports. I have a multi project build and I would like to aggregate the reports of all the subprojects into one report. Attempt using TestReport task (runs the findbugs tasks, but skips the aggregate task saying onlyIf is false. I think that the reportOn doesn’t know what to do with the FindBugs task or the report files.):
def getFindBugsTasks() {
allprojects.collect { it.tasks.withType(FindBugs) }.flatten()
}
def getAllFindBugsReports() {
findBugsTasks*.reports//.html.destination
}
task aggregateFindBugsReport(type: TestReport) {
destinationDir = file("$buildDir/reports/findbugs")
reportOn {
getFindBugsTasks()
//getAllFindBugsReports()
}
}
Attempt creating custom task using DefaultTestReport (fails saying could not determine dependencies of the task):
task aggregateFindBugsReports(type: TestReportAggregator) {
testReportDir = file("${reporting.baseDir}/findBugs")
testResultsDir = file("${buildDir}/test-results")
projects = subprojects
}
import org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport
import org.gradle.api.internal.tasks.testing.junit.result.AggregateTestResultsProvider
class TestReportAggregator extends Copy {
def projects
File testResultsDir
@OutputDirectory
File testReportDir
def TestReportAggregator() {
dependsOn { findBugsTasks }
from { inputTestResultDirs }
into { testResultsDir }
}
@TaskAction
def aggregate() {
def report = new DefaultTestReport()
report.generateReport(new AggregateTestResultsProvider(findBugsTasks), testReportDir)
}
def getFindBugsTasks() {
projects.collect { it.tasks.withType(FindBugs) }.flatten()
}
def getInputTestResultDirs() {
findBugsTasks*.testResultsDir
}
def getAllFindBugsReports() {
def list = []
findBugsTasks.each {
list << it.reports.html.destination
}
list
}
}