【问题标题】:how to let jacoco know sources/classes are outside the module如何让 jacoco 知道源/类在模块之外
【发布时间】:2017-09-13 03:47:12
【问题描述】:

模块 A 是一个包含所有集成测试的独立模块。如果源和测试位于一个模块中,Maven-Jacoco-Sonar 工作正常。

由于模块 A 完全是一个不同的模块,我们无法轻松生成 jacoco 报告。因为,jacoco 无法在模块 A 中找到源来衡量报告的覆盖率。源文件都位于不同的模块中。 jacoco 需要有可用的类文件和源文件才能生成报告。我们需要在生成 jacoco 报告时将它们相应地链接到模块 A,以便可以轻松地将 jacoco-it.exec 拉到 Sonar 以显示覆盖率分析。

目前在这种情况下, 根据 jacoco 代理触发的类,但没有可用的源/类文件

如果有人有解决方案如何实现上述功能,请帮助我。这对我很有帮助。

【问题讨论】:

    标签: maven jacoco


    【解决方案1】:

    尝试将以下内容添加为您的主源代码

     def debugTree = [fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter),
                     fileTree(dir: "${project(":your_module_name").projectDir}/build/intermediates/classes/debug", excludes: fileFilter)]
     def mainsrc = [fileTree(dir:"${project(":your_module_name").projectDir}/src/main/java"),
                         fileTree(dir:"${project.projectDir}/src/main/java")]
     sourceDirectories = files(mainsrc)
     classDirectories = files(debugTree)
    

    这将包括您在创建 jacoco 报告时要使用的外部子模块文件。

    【讨论】:

      【解决方案2】:

      尝试设置 sourceset 变量。

          jacocoTestReport {
              sourceSets project(':module_name').sourceSets.main
              reports {
                  xml.enabled true
      //            enable html report for debugging in local env
      //            html.enabled true
      //            html.destination = file("${buildDir}/jacocoHtml")
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2020-08-08
        • 2013-04-11
        • 2015-01-12
        • 1970-01-01
        • 2019-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多