我在一个项目中添加了一组没有测试的源,我不希望它们破坏我的测试覆盖率统计数据。我以以下方式配置了 Jacoco:
test {
jacoco{
excludes = ['org/bla/**']
includes = ['com/bla/**']
append = false
}
}
jacocoTestReport {
dependsOn test
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled true
html.enabled true
}
classDirectories = fileTree(dir: 'build/classes/main', include: 'com/bla/**')
sourceDirectories = fileTree(dir: 'scr/main/java', include: 'com/bla/**')
}
但无论如何,在生成报告时,Jacoco 还包含来自org.bla的类
有人能帮我吗 ?
编辑
经过一些调试,似乎所有默认输出都添加到org.gradle.testing.jacoco.tasks.JacocoReport#classDirectories
私有方法中org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
使用此类代码时可见:
jacocoTestReport {
classDirectories = files('build/classes/main/com/bla')
println("-----------------------------------------------------------")
getAllClassDirs().each { File file ->
println(file.absolutePath)
}
println("-----------------------------------------------------------")
getAdditionalClassDirs().each{ File file ->
println(file.absolutePath)
}
}
jacocoTestReport << {
println("-----------------------------------------------------------")
getAllClassDirs().each { File file ->
println(file.absolutePath)
}
println("-----------------------------------------------------------")
getAdditionalClassDirs().each{ File file ->
println(file.absolutePath)
}
}
Output
-----------------------------------------------------------
<path_here>\build\classes\main\com\bla
-----------------------------------------------------------
....more text here
-----------------------------------------------------------
<path_here>\build\classes\main\com\bla
<path_here>\build\classes\main
<path_here>\build\resources\main
-----------------------------------------------------------
所以 - 问题是:是否可以以某种方式覆盖org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
方法,或完全覆盖org.gradle.testing.jacoco.plugins.JacocoPlugin
类?