2019-03-26 17:45:32 +00:00
|
|
|
import groovy.io.FileType;
|
|
|
|
|
2019-11-07 18:17:06 +00:00
|
|
|
apply plugin:'jacoco'
|
2019-03-26 17:45:32 +00:00
|
|
|
|
2019-11-07 18:17:06 +00:00
|
|
|
dependencies {
|
|
|
|
jacocoAnt 'org.jacoco:org.jacoco.ant:0.8.2'
|
|
|
|
jacocoAgent 'org.jacoco:org.jacoco.agent:0.8.2'
|
|
|
|
}
|
2019-03-26 17:45:32 +00:00
|
|
|
|
2019-11-07 18:17:06 +00:00
|
|
|
def String jacocoRootExecPath = "$buildDir/jacoco/jacocoMerge.exec"
|
2019-03-26 17:45:32 +00:00
|
|
|
|
2019-11-07 18:17:06 +00:00
|
|
|
delete new File(jacocoRootExecPath) // If the merged exec file (output from jacocoMerge) exists,
|
|
|
|
// jacocoReport & jacocoBranchReport tasks are skipped and
|
|
|
|
// the report is not generated.
|
|
|
|
// So always delete the merged file before the determination
|
|
|
|
// to skip a task is made.
|
2019-03-26 17:45:32 +00:00
|
|
|
|
|
|
|
/*********************************************************************************
|
2019-11-07 18:17:06 +00:00
|
|
|
* Task to merge multiple jacoco execution data files into one
|
2019-03-26 17:45:32 +00:00
|
|
|
*********************************************************************************/
|
2019-11-07 18:17:06 +00:00
|
|
|
task jacocoMerge(type: JacocoMerge) {
|
|
|
|
description = 'Task to merge multiple jacoco execution data files into one.'
|
|
|
|
destinationFile = new File(jacocoRootExecPath)
|
|
|
|
dependsOn { subprojects.findAll { p -> p.plugins.hasPlugin('jacoco') }.test }
|
|
|
|
dependsOn { subprojects.findAll { p -> p.plugins.hasPlugin('jacoco') }.integrationTest }
|
|
|
|
executionData fileTree(rootDir) {
|
|
|
|
include '**/*.exec'
|
|
|
|
}
|
2019-03-26 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
2019-11-07 18:17:06 +00:00
|
|
|
* Task to generate an aggregate jacoco report from subprojects with
|
|
|
|
* Java sourceSets
|
2019-03-26 17:45:32 +00:00
|
|
|
*********************************************************************************/
|
2019-11-07 18:17:06 +00:00
|
|
|
task jacocoReport(type: JacocoReport, group: 'Coverage reports') {
|
|
|
|
description = 'Generates an aggregate Jacoco report from all subprojects'
|
|
|
|
dependsOn 'jacocoMerge'
|
|
|
|
executionData new File(jacocoRootExecPath)
|
|
|
|
|
|
|
|
// Setting these source/class dirs MUST be done in the configuration phase (we used
|
|
|
|
// to do it in a doFirst block but that was deprecated in later gradle builds). However,
|
|
|
|
// we have to delay evaluation of the subprojects (using the '{ }' notation) to wait for
|
|
|
|
// some project attributes (eg: 'sourceSets') to be made available.
|
|
|
|
additionalSourceDirs files({ subprojects.findAll { p -> p.plugins.hasPlugin('jacoco') }.sourceSets.main.java.srcDirs })
|
|
|
|
additionalClassDirs files({ subprojects.findAll { p -> p.plugins.hasPlugin('jacoco') }.sourceSets.main.output })
|
|
|
|
|
|
|
|
reports {
|
|
|
|
html {
|
|
|
|
enabled true
|
|
|
|
destination new File(rootDir.absolutePath + "/jacocoReport")
|
|
|
|
}
|
|
|
|
xml {
|
|
|
|
enabled false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|