Skip to content

Wakaleo Consulting

  Home Blog Site Generation in Maven 3
  • Training and Mentoring in Test Driven Development
  • Expertise in Continuous Integration and Continuous Deployment
  • Training and Mentoring in Test Driven Development
  • Expertise in quality development and testing practices
  • Expert Jenkins/Hudson training and mentoring
  • Expertise in Continuous Integration and Continuous Delivery
  • Training and Mentoring in Test Driven Development
  • Training and Mentoring in Test Driven Development
  • Expertise in Automated Acceptance Tests and ATDD
Site Generation in Maven 3 PDF Print E-mail
Tuesday, 12 October 2010 15:35

So Maven 3 has finally been released, with a host of improvements and significant rework under the hood. Maven 3 is largely backward compatible with Maven 2, so migration from Maven 2 to Maven 3 is usually a very easy process. In this article, we will take a look at the one area where you may have some work to do in the migration process: site generation.

In many ways, this is a very discreet release, with few apparent major new features. However, under the hood it's a different story. The internal architecture of Maven 3 has pretty much been completely rewritten, with Guice as it's IOC framework, and with clean integration points to allow smooth interaction with third-party systems such as IDEs and CI servers. Given this almost-total rewrite of the Maven internals, the extremely high backward compatibility that Maven 3 shows is truly impressive.

Performance is a big feature of this new release, both in terms of general performance, and with the new ability to build modules in parallel, which can be very useful for large, multi-module builds. Maven 3 is more strict about Maven best practices, and will grumble if you don't define version numbers for your plugins or dependencies (as of course you should).

One more significant difference however is site generation. You might use the Maven site generation useful as a central point of documentation about your project, or you may use it simply to generate reports and code quality metrics for use in CI servers such as Hudson or TeamCity. In either case, the mvn site command can come in very handy.

If you have been using the reporting section of the pom.xml file to generate code quality metrics, javadoc reports, and so forth, you may have a little work to do to migrate this feature into Maven 3. Indeed, the reporting and reportSets sections have been deprecated (it won't cause an error with Maven 3, it will just be ignored), and have been replaced by a reportPlugins section in the configuration block of the maven-site-plugin itself. For example, suppose your Maven 2 pom.xml file looks like this:

<project>
  ...
  <reporting>
    <plugins>
      <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-surefire-report-plugin</artifactId>
        <version>2.6</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <formats>
            <format>xml</format>
            <format>html</format>
          </formats>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.6</version>
      </plugin>
    </plugins>
  </reporting>
</project>

This won't work in Maven 3. Instead, you will have to integrate your reports into the maven-site-plugin, as shown here:

<project>
  ...
  <build>
    ...
	 <plugins>
       ...
	   <plugin>
	      <groupId>org.apache.maven.plugins</groupId>
	      <artifactId>maven-site-plugin</artifactId>
	      <version>3.0-beta-2</version>
	      <configuration>
	        <reportPlugins>
	          <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-jxr-plugin</artifactId>
	            <version>2.1</version>
	            <configuration>
	              <aggregate>true</aggregate>
	            </configuration>
	          </plugin>
	          <plugin>
	            <groupId>org.apache.maven.plugins</groupId>
	            <artifactId>maven-surefire-report-plugin</artifactId>
	            <version>2.6</version>
	          </plugin>
	          <plugin>
	            <groupId>org.codehaus.mojo</groupId>
	            <artifactId>cobertura-maven-plugin</artifactId>
	            <version>2.4</version>
	            <configuration>
	              <formats>
	                <format>xml</format>
	                <format>html</format>
	              </formats>
	            </configuration>
	          </plugin>
	          <plugin>
	            <groupId>org.apache.maven.plugins</groupId>
	            <artifactId>maven-checkstyle-plugin</artifactId>
	            <version>2.6</version>
	          </plugin>
	        </reportPlugins>
	      </configuration>
	    </plugin>
	  </plugins>
	</build>
</project>

So you are basically just moving your old reporting plugins into the configuration section of the new maven-site-plugin. You probably should take the opportunity to upgrade your reporting plugins - I haven't come across any incompatibility problems, but you never know.

Maven 3 generally produces better console output than Maven 2, and reporting is no exception. At the end of the mvn site output, you get a nice summary of the reports generated:


[INFO] Generating "Source Xref" report    --- maven-jxr-plugin:2.1
[INFO] Generating "Test Source Xref" report    --- maven-jxr-plugin:2.1
[INFO] Generating "Checkstyle" report    --- maven-checkstyle-plugin:2.6
[INFO] 
[INFO] There are 93 checkstyle errors.
[INFO] Generating "Surefire Report" report    --- maven-surefire-report-plugin:2.6
[INFO] Generating "Cobertura Test Coverage" report    --- cobertura-maven-plugin:2.4
       ...
[INFO] Cobertura Report generation was successful.
[INFO] Generating "CPD Report" report    --- maven-pmd-plugin:2.5
[INFO] Generating "PMD Report" report    --- maven-pmd-plugin:2.5
[INFO] Generating "FindBugs Report" report    --- findbugs-maven-plugin:2.3.1
[INFO] Locale is en
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.315s
[INFO] Finished at: Tue Oct 12 15:23:22 NZDT 2010
[INFO] Final Memory: 37M/98M
[INFO] ------------------------------------------------------------------------

All in all, a pretty straight-forward migration path.

One final comment on Maven site generation might be worth noting - when it first came out, the Maven-generated technical web site was revolutionary. However, nowadays there are other tools that build on Maven's powerful reporting features to take things even further - CI servers like Hudson and TeamCity can make use of the XML reports generated by Maven to provide code quality metrics of their own, and Sonar can even run code quality metrics reporting on any Maven project, without needing to configure the project at all. All these options are worth considering when you try to introduce code quality reporting into your project.

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

Maven  Maven Site Generation 

Trackback(0)
Comments (7)Add Comment
0
...
written by Ben, October 12, 2010
Hmm, but I wonder if they have fixed multi module site links. That's been a problem since first release of 2.0.
0
...
written by Dev Stonez, October 13, 2010
Should the version for the reporting plugins be specified directly (as in Maven 2) or it will be inherited this time from ?
0
...
written by Dev Stonez, October 13, 2010
... continued from above (due to the un-escaped angles, the content was treated as a html tag)...

... inherited this time from . In Maven 2 it was a bit problematic since the reporting plugins versions should be explicitely done in section. I expect now, with Maven 3, to have this fixed, to allow version definition in similar to other plugins.
0
...
written by Dev Stonez, October 13, 2010
it happened again (brrrr ! smilies/angry.gif), so here is the actual content (last try):

============================================

Should the version for the reporting plugins be specified directly (as in Maven 2) or it will be inherited this time from "pluginManagement" ? In Maven 2 it was a bit problematic since the reporting plugins versions should be explicitely done in "reporting" section. I expect now, with Maven 3, to have this fixed, to allow version definition in "pluginManagement" section, similar to other plugins.
0
...
written by Tulio Domingos, November 12, 2010
Great post! I just migrated from Maven 2 and was wondering what happened to the reporting section..Cheers

Tulio

http://tuliodomingos.blogspot.com/
0
...
written by Flávio Silva, December 31, 2010
I could finally generate my project's site!!
many thanks to share that, it was so many hours figuring out how to do, but the documentation of the new 3 version is still not as wide and could only find about version 2...
perfect now...smilies/smiley.gif
0
Site Generation in Maven 3
written by Kannan, April 30, 2011
Thanks for clear instructions. I could get site generated with Maven 3.0.2. The info in maven wiki was also useful, https://cwiki.apache.org/MAVEN/maven-3x-and-site-plugin.html#Maven3.xandsiteplugin-Usingmavensiteplugin2.xwithMaven2.xandmavensiteplugin3.xwithMaven3.x.

Write comment

busy
 

Learning Corner

Upcoming courses

Testing and TDD for Java Developers in Melbourne
3 DAY WORKSHOP
Melbourne - 27-29 March
 
Testing and TDD for Java Developers in Sydney
3 DAY WORKSHOP
Sydney 2-4 April
 
Testing and TDD for Java Developers in Canberra
3 DAY WORKSHOP
Canberra - 1-3 May