Maven Reports in Jenkins
Code quality is a sensitive topic. It affects your maintenance cost as well as your customer satisfaction. Not to mention your developers motivation to work with the code. Who wants to fix ugly code, right?
Discussing code quality always needs hard facts and numbers! So this is a short tutorial how to create some simple reports to analyze some code quality metrics.
Reports
This section will shorty explain the used reports.
Findbugs
FindBugs looks for bugs in Java programs. It is based on the concept of bug patterns. A bug pattern is a code idiom that is often an error
Checkstyle
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.
Cobertura Code Coverage
Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
Surefire Test Report
The Surefire Plugin is used during the test
phase of the build lifecycle to execute the unit tests of an application. It generates reports…
Basic pom.xml
Starting with a basic pom configuration:
<project> ... <properties> <findbugs.version>2.5.2</findbugs.version> <checkstyle.version>2.9.1</checkstyle.version> <surefire.reportplugin.version>2.12.4</surefire.reportplugin.version> <cobertura.version>2.5.2</cobertura.version> </properties> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>${findbugs.version}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>${cobertura.version}</version> <configuration> <formats> <format>xml</format> </formats> </configuration> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>${findbugs.version}</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>${checkstyle.version}</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>${surefire.reportplugin.version}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>${cobertura.version}</version> <configuration> <formats> <format>xml</format> </formats> </configuration> </plugin> </plugins> </reporting> </project>
Jenkins Plugins
You need to install a few jenkins plugins to get a nice integration with your reports.
- Static Analysis Collector Plug-in
- Static Analysis Utilities
- Checkstyle Plug-in
- FindBugs Plug-in
- Jenkins Cobertura Plugin
Project Configuration
Now you need to configure your project to show the results of your reports.
Findbugs and Checkstyle
You can configure them in the “build configuration” tab. There are some limits to set, which influence the representation.
Cobertura
Cobertura is configured in the “post-build actions”. Same configurations as in the findbugs and checkstyle plugin.
Result
On your main page of your project you have some new graphs and links.
Hi Nepomuk,
very nice article! Gives a very good overview for different reporting plugins.
Do you also know JaCoCo for code coverage? In my opinion JaCoco is very smart and works also together with Arquillian.
Ciao, Matthias
Hi Matthias,
I already tested JaCoCo. The Eclipse integration is fantastic and it works smoothly with Java 7.
The setup is as easy as Cobertura. If you have a lot of Eclipse developers this should be your
first choice.
cheers,
Muki
Good write-up, all it’s missing is compiler warnings from ex. Eclipse Java Compiler :)
Good article Nipomuk…. but was curious as to why one needs to do this setup onself…. if you use Sonar…it will do this and much much more…. also, Jenkins has a Sonar plugin….so it is very easy to integrate Sonar into CI cycle….
cheers,
GT
Hi GT,
Well sometimes you don’t need all the big setup in the beginning and just want to get started fast :)
The sonar stuff is really awesome, however in my team we just needed something small, but as
we grow bigger the more we look for stuff like sonar.
cheers,
Muki