ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Maven 2.0: Compile, Test, Run, Deploy, and More
Pages: 1, 2, 3, 4

Plugins and Reports

Maven 2.0 has a wide array of plugins that are available. Unfortunately, since Maven was rewritten, Maven 1.0 plugins won't work and cannot be used with Maven 2.0. However, there are several Maven 2.0 plugins already available for use. The following plugin configuration for pom.xml is an example straight from the Maven 2.0 website. This plugin is used to configure compiler options.



  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.5</source>
        <target>1.5</target>
      </configuration>
    </plugin>
  </plugins>

The Maven reporting plugins can be used to generate different reports that will be available when you generate the project website using mvn site. Here is an example of how to configure one of those plugins using the <reporting> element.

 <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
      </plugin>
    </plugins>
  </reporting>

The Maven Plugin Matrix is really useful for figuring out what Maven plugins are available for which version of Maven.

Maven and Eclipse

How could the world's greatest IDE get any better? With a Maven 2 plugin that assists in searching for dependencies and adds them to pom.xml automatically. Maven has an Eclipse plugin that will enable Maven for any project, although it is best to create your project with Maven first and then generate your Eclipse project file with mvn eclipse:eclipse, just so that you get the directory structure perfect the first time.

You can install the Eclipse plugin through the updater in Eclipse itself using http://m2eclipse.codehaus.org/ as the site for the plugin. After installing and restarting the IDE, you need to configure the Maven plugin in Eclipse's preferences by filling in the location of the local repository. This is an important step, because if the default repository for Eclipse doesn't match your default, Maven will re-download your dependencies. After configuration, import the project into Eclipse, right-click on the project, and choose Maven 2 -> Enable. Now you can go back through that step and you'll have more options like Add Dependency, which will bring up a search box so you can search for dependencies and add them; the plugin will edit your pom.xml file for you.

The plugin will build your project using Maven in much the same way that Eclipse can handle building with Ant. If you would like more information on Eclipse integration with Maven, check out the guide to using Eclipse with Maven 2.x on the Maven site.

On the other hand, if you are an IntelliJ fan, you can accomplish the same task by running mvn idea:idea. These IDE integrations can save ramp-up time for developers. For example, if a developer adds some new aspect to a project, other developers on the team can just re-check out the project files from their source control repository and save the time of each developer having to make the IDE configuration.

Conclusion

Maven 2.0 has many useful features and performs extremely well. The most laudable part of Maven is the use of standard directory structures and deployments. This allows developers to move from project to project and not have to learn anything new about the structure or go through special instructions on how to build it. Practical applications for Maven also extend into custom build systems for large software engineering shops. Maven can be fully scripted and queued to run nightly and deploy distributions as well as send out notifications to users. From the documentation side, it's extremely handy to have the project website tools built in so that when the project build is complete, you can see a current status of all development.

There is no doubt that Maven 2.0 blows Ant out of the water when it comes to scalable build configurations, ease of use, and project management. In the next few years, we'll see more adoption of Maven as the standard in build technology until someone comes along and builds the proverbial "better mousetrap." You can download Maven from the Maven project website listed below.

Resources

Chris Hardin is a Senior Java Architect in Birmingham, Alabama.


Return to ONJava.com.