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
|
if (!project.hasProperty("jacoco")) {
//JaCoCo plugin prevents using Build Cache. We will enable jacoco configuration only when specific property is supplied
//TODO remove this workaround when we migrate to Gradle 5.0 (https://github.com/gradle/gradle/issues/5269)
logger.info "JaCoCo code coverage will not be configured because 'jacoco' project property is not present."
return //don't evaluate this Gradle file any further
} else {
logger.lifecycle "Configuring JaCoCo code coverage because 'jacoco' project property is present."
}
//TODO: Standard JaCoCo coverage doesn't work in Android module
task mockitoCoverage(type: JacocoReport) {
allprojects { currentProject ->
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"]) {}
|