无法从Kotlin Jacoco测试覆盖范围中排除生成的类 [英] Unable to Exclude generated classes from kotlin jacoco test coverage
本文介绍了无法从Kotlin Jacoco测试覆盖范围中排除生成的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从jacoco覆盖率报告中排除一些生成的类. groovy可以正常工作,但是转换为Kotlin后就无法正常工作
I am trying to exclude some generated classes from jacoco coverage report. Which is working fine with groovy but after converting to Kotlin it's not working
tasks.withType<JacocoCoverageVerification> {
afterEvaluate {
files(classDirectories.files.forEach() {
fileTree(it).apply {
exclude("com/generate/**")
}
})
}
violationRules {
rule {
limit {
minimum = BigDecimal(0.30)
}
}
}
}
tasks.getByName("check")
.dependsOn(tasks.getByName("jacocoTestCoverageVerification"))
但是违反规则很好地工作.
But violation rule working perfectly.
推荐答案
这是kotlin
上jacoco plugin
的局限性.由于classDirectories
不是最终的,所以我们不能采用旧的方式.我们需要使用方法classDirectories.setFrom
来设置值.
It is a limitaion with jacoco plugin
on kotlin
. Since the classDirectories
is not final, we cant go with the old way. We need to use the method classDirectories.setFrom
to set the value.
tasks.withType<JacocoCoverageVerification> {
violationRules {
rule {
limit {
minimum = BigDecimal(0.62)
}
}
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("com/generate/**")
}
}))
}
}
tasks.withType<JacocoReport> {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("com/generate/**")
}
}))
}
}
这篇关于无法从Kotlin Jacoco测试覆盖范围中排除生成的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文