Combine Gradle multi-project test results and coverage into one

Modify build.gradle of the root project as follows

allprojects {
    apply plugin: 'java'
    apply plugin: 'jacoco'

    repositories {
        jcenter()
    }

    jacoco {
        toolVersion = '0.7.9'
    }
}

subprojects {
    test {
        reports.html.enabled = false
    }

    jacocoTestReport {
        additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
        sourceDirectories = files(sourceSets.main.allSource.srcDirs)
        classDirectories =  files(sourceSets.main.output)
        reports {
            html.enabled = true
            xml.enabled = true
            csv.enabled = false
        }
    }
}

task testRootReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    reportOn subprojects.tasks.test
}

task jacocoRootReport(type: JacocoReport) {
    dependsOn = subprojects.test
    additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
    sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
    classDirectories =  files(subprojects.sourceSets.main.output)
    executionData = files(subprojects.jacocoTestReport.executionData)
    reports {
        html.enabled = true
        xml.enabled = true
        csv.enabled = false
    }
}

task report(dependsOn: ['testRootReport', 'jacocoRootReport'])

command

./gradlew test report

result

.
└── build
    └── reports
        ├── allTests
        │   └── index.html etc...
        └── jacoco
            └── jacocoRootReport
                └── html
                    └── index.html etc...

reference

https://gist.github.com/aalmiray/e6f54aa4b3803be0bcac http://clash-m45.hatenablog.com/entry/2015/01/24/162621

Recommended Posts

Combine Gradle multi-project test results and coverage into one
Output test coverage with clover + gradle
Getting started with Gradle (until you create a Java project and combine external libraries into one executable JAR)
Build and test Java + Gradle applications with Wercker