Get the most out of Maven 2 site generation

Steps for creating a Maven-based Website

Team communication is an essential part of any project. And wasting time looking for technical project information can be costly and frustrating. Clearly, any IT project will benefit from having its own dedicated technical Website.

That's where the Maven site generator steps in. With little effort, you can have a professional-quality, low maintenance project Website up and running in no time. Maven lets you generate a one-stop center of information about your project, including:

  • General project information such as source repositories, defect tracking, and team members
  • Unit test and test coverage reports
  • Automatic code reviews with Checkstyle and PMD
  • Configuration and versioning information
  • Dependencies
  • Javadocs
  • Source code in indexed and cross-referenced HTML format
  • And much more

Maven sites are frequently used on open source projects (see Resources for some examples). A typical project site contains information about the project, largely derived from the pom.xml file, some generated reports (unit tests, Javadocs, Checkstyle code audits, etc.), as well as some project-specific content matter.

In this article, we will walk though what you need to know to get a Maven site up and running in minimal time. Note: The source code used in this tutorial can be downloaded from Resources.

Iteration 1: The project information section

Your Maven site will be one of the first places a newcomer will look to get to know your project, and the project information page is the place they will expect to find a summary of your project's organization. This part of the Website is built entirely using information found in the pom.xml file. The default pom.xml file created will look something like this:


<project xmlns="" xmlns:xsi="" xsi:schemaLocation="> <modelVersion>4.0.0</modelVersion> <groupId></groupId> <artifactId>HotelWeb</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Maven Quick Start Archetype</name> <url></url>

<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>

Now you will want to add some details about your project. All zones are optional, but you should put as much information as is relevant to your project. The following sections discuss some useful items to add.

Project name and description

Add an appropriate project name, a description, and the project site URL. This appears on your project's homepage, so don't be stingy:

   <name>Hotel Database tutorial application</name>
   <description>Write a few paragraphs to say what your project is about.</description>

Issue tracking

Now put the name and URL of your project's issue management system (Bugzilla, Jira, Scarab, or your own favorite issue tracking system), using the issueManagement tag:


Continuous integration

If your project uses a continuous integration tool of some sort, such as CruiseControl or Continuum, you can provide details in the ciManagement tag, as shown in the code below. (If you are not, consider using one!) Maven 2 integrates well with Continuum: you can install a Maven 2 project onto a Continuum server just by providing the pom.xml file.


The project team

People like to know who they are working with, especially these days, when a project team can be spread across organizations and continents. In the developers section, list team member details. The timezone field is useful for international teams; this field is offset from Greenwich Mean Time (GMT), or London time, and lets people see what time it is wherever the team member is located. For example, -5 is for New York time, +1 for Paris, and +10 for Sydney.

         <name>Duke Java</name>
            <role>Project Manager</role>

Mailing lists

If your project uses mailing lists, describe them in the mailingLists page. A typical mailing list configuration might look like this:

       <name>HotelDatabase project mailing list</name>

The source repository

Another vital part of any project is the source repository. The scm tag lets you document the configuration of your source repository, both for the Maven Website and for use by other plug-ins. If you are using CVS or Subversion, the source repository page will also give detailed, tool-dependent instructions on how to use the repository. Here is an example of a typical SCM (software configuration management) configuration:


Now you can try out your new Maven site! The command to generate the Maven site is: mvn site.

Your site will be generated in target/site. Take a look at the project information link; you should find everything you just entered and more (see Figure 1)!

Figure 1. The project information zone in your new Maven 2 project site

Iteration 2: Add reports

Maven also provides an extensive range of plug-ins for automatic report generation. Report generation in Maven 2 is easy: you just add the report plug-ins you need into the reporting section at the end of the pom.xml file.


Most likely, you will want to start by publishing your classes' Javadocs. This is as simple as adding javadoc to the reporting section of your pom.xml file. While you're at it, add the jxr plug-in as well; this will generate an indexed and cross-referenced HTML version of your source code:


Unit-test reports

Writing unit tests for as much code as possible is highly recommended. Maven fully integrates unit testing into the build process—by default, all unit tests run at each build. Publishing test results for all to see is beneficial, as it tends to encourage developers to fix any broken unit tests.

The surefire plug-in runs all the unit tests and generates a detailed report:


Test coverage

Test coverage can be a useful indication of the quality of your unit tests. It basically tells you how much of your code is actually run by your unit tests, which, in turn, can give you a good idea of the tests' quality. In some projects, requiring a certain percentage of test coverage in all classes is recommended. Tools such as Clover (a robust commercial test coverage tool) or Cobertura (a promising open source tool that replaces the Maven 1 JCoverage plug-in) generate test coverage reports. Clover has a proven ability to perform test coverage for large projects, where other tools would often fail. Figure 2 illustrates a Clover test coverage report.

Figure 2. A Clover-generated test coverage report

To date, only the Clover plug-in is available for Maven 2, though Cobertura is in development at the time of this writing.

To add a Clover report to your Maven site, simply add the maven-clover-plug-in to the reporting section:


Code analysis

Automatic code analysis is a useful way of improving code quality and encouraging good coding habits. Checkstyle runs a wide range of tests aimed at enforcing coding standards and best practices. PMD concentrates more on semantic errors and potential bugs. Both can provide useful information, though you may have to fine-tune them (especially Checkstyle) to obtain only the errors meaningful for your project.

Sometimes you will need to pass parameters to a plug-in. In Maven 2, you can do this using the configuration tag, which will inject the parameter value into the plug-in. In the pmd plug-in, set the targetjdk parameter to 1.5 so that PMD will be able to handle Java 1.5 source code. You can also specify other parameters, such as the rules to be used, the output format, and whether hyperlinks to the code source should be generated:


<reporting> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-pmd-plugin</artifactId> <configuration> <targetjdk>1.5</targetjdk> <rulesets> <ruleset>/rulesets/basic.xml</ruleset> <ruleset>/rulesets/controversial.xml</ruleset> </rulesets> <format>xml</format> <linkXref>true</linkXref> <sourceEncoding>utf-8</sourceEncoding>

<minimumTokens>100</minimumTokens> </configuration> </plugin> </plugins> </reporting>

Change and configuration management

Documenting changes is important in any project. Maven 2 provides a couple of useful features to make this task a little easier.

The changes-maven-plugin plug-in uses a special XML file (src/changes/changes.xml) to track releases and changes in each release. This file looks something like this:

 <?xml version="1.0" encoding="ISO-8859-1"?>
      <title>Hotel Database tutorial application</title>
      <author email=">Duke Java</author>
      <release version="current" description="Current work version>    
           <action dev="Duke Java" type="add>
               A new cool feature.
      <release version="1.0.1" date="2005-11-18" description="Release fix>   
           <action dev="Duke Java" type="add>
               Added a cool feature.
           <action dev="Duke Java" type="fix" issue="1254>
               Fixed a nasty bug.
           <action dev="Duke Java" type="delete>
               Removed a feature that nobody liked.

Here, you list your releases and describe the actions associated with each release: a new feature or evolution (add), a bug fix (fix), or something removed (delete). You should detail the modification, who made the change, and what issue was addressed. Using this file gives a clearer and more readable record of changes and release history.

Now add the changes plug-in to the Maven 2 reports:


Figure 3 shows an example of a real-world change report.

Figure 3. A real-world change report
1 2 Page 1
Page 1 of 2