gpt4 book ai didi

java - 如何在 Gradle 中将源代码添加到 Jacoco 报告中

转载 作者:行者123 更新时间:2023-11-30 07:19:26 25 4
gpt4 key购买 nike

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

为此,JacocoReport documentation从 Gradle 2.14 开始,列出了两对指令:

  • sourceDirectoriesclassDirectories
  • additionalSourceDirs & additionalClassDirs

但是,两者都期望有一个 FileCollection 以及所有项目源集和输出文件的某种粘合,需要调用 someJavaProjectSourceSet.srcDirs 上的 files() 来获取代码行级审核,报告中嵌入了实际源代码。

有更好的方法吗?

最佳答案

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
}

简单!

关于java - 如何在 Gradle 中将源代码添加到 Jacoco 报告中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37831402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com