一、Gradle配置信息
apply plugin: "jacoco"
jacoco {
toolVersion = "0.8.4"
reportsDir = file("$buildDir/customJacocoReportDir")
}
jacocoTestReport {
reports {
html.enabled true
csv.enabled false
xml.enabled true
xml.destination file("$buildDir/jacocoXml.xml")
html.destination file("$buildDir/jacocoHtml")
}
afterEvaluate {
getClassDirectories().setFrom(
classDirectories.files.collect {
fileTree(dir: it,
exclude: ['需要排除的路径, it路径是classes'])
}
)
}
}
test {
jacoco {
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
二、生成报告
- 点击执行test
- 点击执行jacocoTestReport
- 查看生成报告

