A few words of thanks would be greatly appreciated.

Code Quality Reporting with Maven

By improving the code quality of a program, one will also improve its robustness and maintainability. This guide will teach you how to generate code quality reports for a Maven project.

How To Generate Project Site and Reports with Maven

Maven gives you the ability to generate a HTML site that describes your project. You can use the
mvn site
command to generate your project site.

Once done, open the target/site/index.html file to view the site:

The project site will usually contain technical information about the project’s architecture (dependencies, plug-ins…); you will need to enrich it with the data generated by Maven's report plug-ins (as defined in your project configuration file).

Code Analysis and Reporting Plug-ins for Maven

Below is an excerpt that can be incorporated into your configuration file (pom.xml). It features a couple of standalone plug-ins for code analysis and reporting. Each plug-in will generate a specific report on the project site.

      <!-- The Failsafe Plugin is designed to run integration tests while the 
      Surefire Plugin is designed to run unit tests. -->
        <!-- The JXR Plugin generates a cross-reference of the project's sources. -->
      <!-- The Javadoc Plugin generates javadocs using the Javadoc tool. -->
      <!-- The Surefire Report Plugin generates reports for unit and integration 
        tests. -->
      <!-- The Checkstyle Plugin generates a report regarding the code style 
        used by the developers. -->
      <!-- The PMD plugin generates PMD and CPD reports using the PMD code 
        analysis tool. -->
          <!-- <ruleset>rulesets/java/controversial.xml</ruleset> -->
      <!-- FindBugs Plugin looks for bugs in Java programs. It is based on 
        the concept of bug patterns. -->

N.B. These plug-ins were given as examples. Click plug-ins to discover the full list of available plug-ins.

How To Generate Reports in Maven

Before you create the project site, it is important to run unit and integration tests for each of the new plug-ins. You can, for example, use the
mvn verify site
command to generate a project site that will already include the results of the unit and integration tests.

How To View Reports in Maven

Click on My Project > Project Documentation > Project Reports to view the reports:

Source XRef

This report will allow you to view the source code of the project:

Test Source Xref

This report will allow you to view a cross-reference version of the project's test source code.

Java Docs

This report will contain the JavaDoc API documentation:

Test Java Docs

This report will contain the Test JavaDoc API documentation.

Surefire Report

This report will contain the results for unit testing:

Failsafe Report

This report will contain the results for integration testing.


This report will list all the violations of the standard syntax rules in Java:

The rules behind the errors messages can be edited through a Custom Checkstyle Checker Configuration.


This report will highlight duplicate code blocks in the project:

Edit the
parameter to define the minimum code length.


This report will highlight poor code construction (in violation with the current PMD Ruleset) that may potentially lead to errors:

Edit the
parameter to change the default PMD Ruleset.


Maven will create a source code report with FindBugs Library. This extensive report will list the possible errors in your code:

Compile Your Reports with SonarQube

SonarQube is an open source platform that allows you to compile the information from your various reports, assess the quality of your code, and compare your project with others.

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Code Quality Reporting with Maven », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!