Gradle Jacoco - 覆盖报告包括配置中排除的类 [英] Gradle Jacoco - coverage reports includes classes excluded in configuration
问题描述
我向项目中添加了一组没有测试的源代码,我不希望它们破坏我的测试覆盖率统计信息。我以下面的方式配置了Jacoco:
test {
jacoco {
excludes = ['org / bla / **']
includes = ['com / bla / **']
append = false
}
}
jacocoTestReport {
dependsOn测试
description =运行测试后生成Jacoco覆盖率报告。
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中的
org.gradle.testing.jacoco.tasks.JacocoReport#classDirectories
.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)
}
}
输出
----------------- ------------------------------------------
< path_here> \build\classes\main\com\bla
------------------------------- ----------------------------
.... more text here
------- -------------------------------------------------- -
\build\classes\main\com\bla
\build\classes\main
\build\resources\main
------------------------------------- ----------------------
所以 - 问题是:是否可以重写 org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
方法,或者完全覆盖 org.gradle.testing.jacoco.plugins.JacocoPlugin
class?
好的,找到一个解决方法:
jacocoTestReport.doFirst {
classDirectories = files('build / classes / main / com / bla')
}
这会覆盖由JacocoPlugin类设置的classDirectories。
I added to a project a set of sources that don't have tests and I don't want them spoil my test coverage statistics. I configured Jacoco in the next way :
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/**')
}
But anyway, when generating the report, Jacoco also includes classes from org.bla
Can someone help me ?
EDIT
After some debugging, it appears that all default outputs are added to org.gradle.testing.jacoco.tasks.JacocoReport#classDirectories
in a private method org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
That's visible when using such code :
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
-----------------------------------------------------------
So - the question is : is it possible to override somehow org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
method, or override completely org.gradle.testing.jacoco.plugins.JacocoPlugin
class ?
Ok, found a workaround :
jacocoTestReport.doFirst{
classDirectories = files('build/classes/main/com/bla')
}
This overrides classDirectories set by JacocoPlugin class.
这篇关于Gradle Jacoco - 覆盖报告包括配置中排除的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!