JaCoCo与微服务项目架构?

时间:2016-08-17 17:51:25

标签: gradle code-coverage jacoco

我的项目由java中的6个微服务组成,我试图弄清楚如何将Jacoco的html报告合并到一个整体报道中。现在我最终得到了每个服务的报告,最好有一个聚合的服务,这样我就可以更容易地将它放入我们的CI以获得可见性等。

我尝试过在网络搜索中找到的各种各样的东西,但是当我尝试这些建议时,我最终会得到一个空的覆盖文件。

这是我的gradle文件:

subprojects {
apply plugin: 'jacoco'
jacoco {
    toolVersion = "0.7+"
    reportsDir = file("$buildDir/reports/customJacocoReportDir")
}
jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
        html.destination "$buildDir/reports/jacocoHtml"
    }
}
test {
finalized by jacocoTestReport
...
}

我运行gradle测试来运行测试并使用上面的服务获得每个服务的报告输出,但是我真的很难将它们合并到一个单独的html报告中。如果有人成功完成,请告诉我。谢谢。

1 个答案:

答案 0 :(得分:2)

At the moment we have the same kind of problem, the jacoco agent has a maven goal called "merge". You can specify the source files and run it:

jacoco:merge

Full name:

org.jacoco:jacoco-maven-plugin:0.7.8-SNAPSHOT:merge

Description:

Mojo for merging a set of execution data files (*.exec) into a single file

Attributes:

  • Requires a Maven project to be executed.
  • The goal is thread-safe and supports parallel builds.
  • Since version: 0.6.4.
  • Binds by default to the lifecycle phase: generate-resources.
<fileSets>
  <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
    <directory>${project.build.directory}</directory>
    <includes>
      <include>*.exec</include>
    </includes>
  </fileSet>
</fileSets>

Actual link: http://www.eclemma.org/jacoco/trunk/doc/merge-mojo.html

Hope it helps :D