【发布时间】:2021-12-30 09:59:22
【问题描述】:
我需要使用 JaCoCo Gradle 插件为我的多模块 Gradle 项目创建一个聚合代码覆盖率报告,类似于 Maven 的 jaoco-maven-plugin 的 jacoco:aggregate-report 生成的报告。
过去几天我一直在谷歌上搜索解决方案,但到目前为止没有任何效果。大多数建议的解决方案都涉及在根项目中定义 JacocoReport 类型的任务,该任务汇总执行数据并生成 html 代码覆盖率报告。但是,到目前为止,我尝试的所有操作要么因错误而失败,要么不生成任何报告。
比如我试过的这段代码sn-p:
def publishedProjects = subprojects.findAll()
task jacocoRootReport(type: JacocoReport) {
dependsOn(publishedProjects.test)
additionalSourceDirs = files(publishedProjects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(publishedProjects.sourceSets.main.allSource.srcDirs)
classDirectories = files(publishedProjects.sourceSets.main.output)
executionData = files(publishedProjects.jacocoTestReport.executionData)
doFirst {
executionData = files(executionData.findAll { it.exists() })
}
reports {
html.enabled = true
xml.enabled = false
}
}
给出错误groovy.lang.GroovyRuntimeException: Cannot set the value of read-only property 'additionalSourceDirs' for task ':jacocoRootReport' of type org.gradle.testing.jacoco.tasks.JacocoReport
我使用的 Gradle 版本是 7.3。不幸的是,我对 Gradle 还是很陌生,我仍然无法摆弄我发现的代码 sn-ps 以使它们适用于我的情况。
任何帮助将不胜感激。非常感谢您。
【问题讨论】:
标签: gradle aggregate code-coverage jacoco