About Nepomuk Seiler

Nepomuk Seiler is a information sience student at the Ludwigs-Maximilians-University Munich. He uses Scala for machine learning tasks and web development with play. Also he provided some small contributions to the Eclipse community.

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

FindBugs Analysis

FindBugs Analysis

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.

Checkstyle Analysis

Checkstyle Analysis

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.

Cobertura Report

Cobertura Report

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…

Surefire Testreport

Surefire Testreport

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.

Project Configuration

Now you need to configure your project to show the results of your reports.

Findbugs and Checkstyle

FindBugs and Checkstyle

FindBugs and Checkstyle

You can configure them in the “build configuration” tab. There are some limits to set, which influence the representation.

Cobertura

Cobertura Config

Cobertura Config

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.

Jenkins Trend Graphs

Jenkins Trend Graphs

 

Jenkins Navbar

Jenkins Navbar


 

Reference: Maven Reports in Jenkins from our JCG partner Nepomuk Seiler at the mukis.de blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

5 Responses to "Maven Reports in Jenkins"

  1. 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

    • Nepomuk says:

      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

  2. dleh says:

    Good write-up, all it’s missing is compiler warnings from ex. Eclipse Java Compiler :)

  3. GT says:

    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

  4. Nepomuk says:

    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

Leave a Reply


9 − = seven



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close