Maven 3 Site Plugin – How To

Creating various helpful reports in a Maven based project is quite easy and straight forward. Such reports vary from simple javadoc to dependency reports and code coverage analysis and having them can be a major advantage during development. In the following post, I present an understandable how-to of generating these reports.

Configuration

Site and report generation is not a base feature of Maven (anymore [see footnote below]) , instead there is a plugin that is responsible for this tasks. The site plugin can be configured in the plugins section of a pom.xml. The configuration itself can contain several report plugins. The following snippet configures the site plugin and adds a number of useful report plugins to it. Simply copy this configuration to your personal pom.xml and adopt any parameters to your needs. Make sure to remove or replace the configuration file location within the maven-checkstyle-plugin.

 
<build>
<plugins>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-site-plugin</artifactId>
  <version>3.0-beta-3</version>
  <configuration>
    <reportPlugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.2</version>
        <reports>
          <report>index</report>
          <report>project-team</report>
          <report>license</report>
          <report>mailing-list</report>
          <report>dependencies</report>
          <report>dependency-convergence</report>
          <report>plugin-management</report>
          <report>cim</report>
          <report>issue-tracking</report>
          <report>scm</report>
          <report>summary</report>
        </reports>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.6</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.7</version>
      </plugin>     
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <!-- Adopt config location to your needs, or remove configuration entry completly to use default version.
          <configLocation>http://stud.hs-heilbronn.de/~nischmid/development/checkstyle-config.xml</configLocation>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>2.3.1</version>
        <configuration>
          <argLine>-Xmx256m</argLine>
          <argLine>-XX:MaxPermSize=256m</argLine>
        </configuration>
        <!-- Usually findbugs needs a lot of memory, change these values if needed. -->
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jdepend-maven-plugin</artifactId>
        <version>2.0-beta-2</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>taglist-maven-plugin</artifactId>
        <version>2.4</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <linkXref>true</linkXref>
          <minimumTokens>100</minimumTokens>
          <minimumPriority>3</minimumPriority>
          <!-- Change minimum priority to see more or less messages -->
          <targetJdk>1.6</targetJdk>
        </configuration>
      </plugin>
    </reportPlugins>
  </configuration>
</plugin>
</plugins>
</build>

 

Report generation

Once, your configuration is set up, you can trigger a report generation with the command mvn site. Depending on the reports used, this may take a while. The final reports will be placed within the target folder. Just open target/site/index.html and you should see something similar to the following screenshot. Click on one of the two red-circled links to expand the report sections. Enjoy reading through the reports and improving your code.

Example Page - Maven Site Plugin

Note: With the introduction of Maven 3, there have been changes in the area of site and report generation, thus the shown pom.xml snippet does only work for Maven 3.0 or later.