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.
Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

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


1 − = zero



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books