1

在 Gradle 中,当您有多个项目时,您可能希望从一个项目生成 Jacoco 测试覆盖率报告,并将其他项目的类显示在报告中。

为此,来自 Gradle 2.14 的JacocoReport 文档列出了两对指令,称为:

  • sourceDirectories&classDirectories
  • additionalSourceDirs&additionalClassDirs

但是,两者都期望单个 FileCollection 和所有项目源集和输出文件的胶水,需要调用files()onsomeJavaProjectSourceSet.srcDirs才能获得代码行级别的审计,并在报告中嵌入实际源代码。

有没有更好的办法 ?

4

1 回答 1

3

sourceSets指令将其他源集添加到报告中,包括源代码和类文件。

尽管由于某种原因它没有出现在插件文档中,但这实际上是插件本身在默认jacocoTestReport任务中添加当前项目的文件的方式。

/**
 * Adds a source set to the list to be reported on.
 * The output of this source set will be used as classes to include in the report.
 * The source for this source set will be used for any classes included in the report.
 *
 * @param sourceSets one or more source sets to report on
 */
public void sourceSets(final SourceSet... sourceSets)

要包含来自其他项目的源集,您可以执行以下操作:

jacocoTestReport {
    sourceSets project(':myAlphaProject').sourceSets.main
    sourceSets project(':myBetaProject').sourceSets.main
}

简单的 !

于 2016-06-15T09:27:25.817 回答