sbt-jacoco
sbt-jacoco copied to clipboard
Merge reports for multi project builds
I have a aggregated build eg (http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Multi-Project.html) and I would like to get a single merged coverage report.
Currently each sub project has a coverage report which makes it hard to understand exactly what is and isn't covered.
The workaround I use right now is an ant script: http://stackoverflow.com/questions/18737433/how-to-combine-jacoco-reports-from-multiple-sub-projects
Something like:
<target name="merge-jacoco">
<delete dir="merged-report" />
<delete file="merged.exec" />
<jacoco:merge destfile="merged.exec">
<fileset dir="target/scala-2.10/jacoco" includes="*.exec" />
<fileset dir="modules/services/target/scala-2.10/jacoco" includes="*.exec" />
<fileset dir="modules/common/target/scala-2.10/jacoco" includes="*.exec" />
<fileset dir="modules/api/target/scala-2.10/jacoco" includes="*.exec" />
</jacoco:merge>
</target>
Definitely not the best solution, but it works well enough. I would love to have the root report contain the report for all sub projects though just by running jacoco:cover
.
There's already a merge action in the code (for merging integration testing with unit testing), so this should hopefully be easily generalizable.
One use case that I found problematic with scct was counting cross-sub-project calls towards coverage. We wanted to see not just unit test coverage, but also functional test coverage.
The hammer approach was wire up the build to overlay all of the sources and concatenate all of the classpaths into one "uber" project, and run the coverage tool on that. This required an enormous amount of messing around with SBT.
Could jacoco4sbt support this use case?
I haven't yet had a look at how exactly sbt's project aggregation works internally, so I don't know how hard it would be to "redirect" all the subproject classpaths to the jacoco configuration. - But basically, I think that's what's required for the "hammer approach" to work.
This is the build code that we used: http://pastie.org/8329946 . Hairy...
I'm optimistic that things might be easier with jacoco4sbt. One would need to rewire internalDependencyClasspath in jacoco
to point at the instrumented classes of sub projects that you depend on, and of course be able to merge the coverage results together as multiple test runs would contributed to the coverage of a single class.
Thanks. - Doesn't look too bad, actually. Some copy/paste that could be removed. What's left then looks like good inspiration. :)