/
coverage.gradle
55 lines (46 loc) · 1.76 KB
/
coverage.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
task mockitoCoverage(type: JacocoReport) {
allprojects { currentProject ->
// These tests do not have a `test` task.
if (currentProject.name in ['android']) {
return
}
// We only run these tests on Java 9+
if (currentProject.name in ['module-test'] && !JavaVersion.current().isJava9Compatible()) {
return
}
// We only run these tests on Java 8
if (currentProject.name in ['errorprone'] && JavaVersion.current().isJava9Compatible()) {
return
}
plugins.withId("java") {
mockitoCoverage.sourceSets currentProject.sourceSets.main
apply plugin: "jacoco"
jacoco {
toolVersion = '0.8.2'
if (currentProject != rootProject) { //already automatically enhanced in mockito main project as "java" plugin was applied before
applyTo test
}
test.jacoco.destinationFile = file("${currentProject.buildDir}/jacoco/test.exec")
}
mockitoCoverage.executionData(files(test.jacoco.destinationFile).builtBy(test))
}
}
reports {
xml.enabled true
html.enabled true
html.destination file("${buildDir}/jacocoHtml")
}
doFirst {
classDirectories.from = classDirectories.files.collect {
fileTree(
dir: it,
exclude: ['**/org/mockito/internal/util/concurrent/**']
)
}
executionData.from = executionData.files.findAll { it.exists() }
}
doLast {
logger.lifecycle "Jacoco HTML created: file://${new File(reports.html.destination, "index.html").toURI().path}"
}
}
task coverageReport(dependsOn: ["mockitoCoverage"]) {}