问题
My project consists of 6 microservices in java and I am trying to figure out how to merge the html reports from Jacoco into one overall coverage report. As it stands now I end up with a report for each service and it would be nice to have an aggregated one so I can more easily put it into our CI for visibility etc.
I've tried various things I've found on web searches, but I end up with an empty coverage file when I try those suggestions.
Here is my gradle file:
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
...
}
I run gradle test to run the tests and get the report output per service using the above, but I am really stumped on how to merge them into a single html report. If anyone has done this successfully please let me know. Thank you.
回答1:
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
来源:https://stackoverflow.com/questions/39003273/jacoco-with-microservice-project-architecture