JaCoCo Jenkins Plugin
Join the DZone community and get the full member experience.
Join For Free
In my post about JaCoCo and MavenI wrote about the problems of using the JaCoCo Maven plugin in multimodule Maven projects because of having one report for each module separately instead of one report for all modules, and how it can be fixed using JaCoCo Ant Task.
In this post we are going to see how to use the JaCoCo Jenkins plugin to achieve the same goal of Ant Tasks and have overall code coverage statistics for all modules.
The first step is installing the JaCoCo Jenkins plugin.
Go to Jenkins -> Manage Jenkins -> Plugin Manager -> Available and find JaCoCo Plugin
The next step, if it is not done already, is configuring your JaCoCo Maven plugin into parent pom:
<build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
And finally a post-action must be configured to the job responsible for packaging the application. Note that in previous pom file reports are generated just before the package goal is executed.
Go to Configure -> Post-build Actions -> Add post-build action -> Record JaCoCo coverage report.
Then we have to set folders or files containing JaCoCoXML reports, which are using the previous pom to **/target/site/jacoco/jacoco*.xml, and also set when we consider that a build is healthy in terms of coverage.
Then we can save the job configuration and run the build project.
After the project is build, a new report will appear just under the test result trend graph, called code coverage trend, where we can see the code coverage of all project modules.
From the left menu, you can enter into Coverage Report and see code coverage of each module separately.
Furthermore, visiting the Jenkins main page will give you a nice quick overview of a job when you mouse over the weather icon as shown:
Keep in mind that this approach for merging code coverage files will only work if you are using Jenkins as a CI system. Ant Task is a more generic solution and can also be used with the JaCoCo Jenkins plugin.
We Keep Learning,
Alex.
Published at DZone with permission of Alex Soto, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments