我正在尝试使用Gradle任务为Android Studio项目创建Jacoco报告。我想从报告中排除一些未经测试的文件,但它们仍然出现在网络报告中。
这是我定义的Gradle任务:
apply plugin: 'jacoco'
jacoco {
// Use this version for upper ones are broken (with Gradle)
// https://github.com/jacoco/jacoco/issues/288
toolVersion = "0.7.1.201405082137"
}
def coverageSourceDirs = [
'src/main/java/....',
]
task createJacocoReport(type: JacocoReport) {
println ":${project.name}:Generating Jacoco reports"
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
xml.destination = "${buildDir}/jacocoReport.xml"
csv.enabled = true
csv.destination = "${buildDir}/jacocoReport.csv"
html.enabled = true
html.destination = "${buildDir}/jacocoHtml"
}
classDirectories = fileTree(dir: './build/intermediates/classes/release',
excludes: ['**/R$*.class',
'**/R.class',
'**/android/**/*.class',
'**/google/**/*.class',
'**/Activities/*.class',
'**/Fragments/*.class',
'**/Views/*.class',
'**/NativeImplementations/*.class',
'**/BuildConfig.class',
'**/CameraDefaultConfig.class'])
sourceDirectories = files(coverageSourceDirs)
executionData = files("./build/jacoco/testReleaseUnitTest.exec")
}
我用以下方式启动此任务:
check.finalizedBy(createJacocoReport)
任何人都知道发生了什么?我正在使用带有Gradle Plugin 2.1.0的Android Studio 2.1.1。
谢谢!
答案 0 :(得分:1)
我已经解决了这个问题,用包含一个替换排除列表。即使我不明白这是什么原因,如果有人有想法......