Maven 2

From HaFrWiki
Jump to: navigation, search

Maven 2 [1] is a through development of Maven (See also the Maven site). Information on maven can be found at the Apache Maven Site and on the Mojo Codehaus site.

On the maven site there are 2 excellent starting guides:

Starting maven 2

To start just begin with:

 mvn clean install

Builds all the modules, and installs them in the local repository. The local repository is created in your home directory (or alternative location that you created it), and is the location that all downloaded binaries and the projects you built are stored. Normally this location is %USERPROFILE%/.m2

Phases and Goals

The most common default lifecycle phases executed

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project

Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, package executes jar:jar if the project type is a JAR, and war:war is the project type is - you guessed it - a WAR.
An interesting thing to note is that phases and goals may be executed in sequence.

   mvn clean dependency:copy-dependencies package

This command will clean the project, copy dependencies, and package the project (executing all phases up to package, of course).

Missing something

In case something missing you get:

  1. xxx:maven-simian-plugin:plugin:1.6.1
    Try downloading the file manually from the project website.

Then, install it using the command:

     mvn install:install-file 
              -DgroupId=xxx -DartifactId=maven-simian-plugin 
              -Dversion=1.6.1 -Dpackaging=plugin 

Alternatively, if you host your own repository you can deploy the file there:

     mvn deploy:deploy-file 
               -DgroupId=xxx -DartifactId=maven-simian-plugin 
               -Dversion=1.6.1 -Dpackaging=plugin -Dfile=</path/to/file> 
               -Durl=[url] -DrepositoryId=[id]

Path to dependency:

  1. xxx:plsql:jar:1.0-SNAPSHOT
  2. xxx:maven-simian-plugin:plugin:1.6.1

1 required artifact is missing.


A useful place to look for Maven2 repository are


Maven 2 uses the settings file to configure settings in the settings.xml file located in the conf directory. A schema is available at: Configuration Example


Maven is - at its heart - a plugin execution framework; all work is done by plugins. Look at the links below for a specific goal to execute. The most common plugins are listed below

Core Description
clean Clean-up after build
compiler Compile Java source
deploy Deploy the build artifacts tot he remote repository
install Install the build artifacts tot he output directory
resources Copy the resources tot he output directory for including in the JAR
site Generate a site for the current project.
surefire Run the JUnit tests in an isolated classloader
verifier Verify the existenceof certain conditions.
Tools Description
ear Generate an EAR from the current project.
ejb Build an EJB from the current project.
jar Build a JAR from the current project.
rar Build a RAR from the current project.
war Build a WAR from the current project.
Reporting Description
changelog Generate a list of recent changes from your SCM.
changes Generate a report from issue tracking or a change document.
checkstyle Generate a checkstyle report.
clover Generate a Clover report.
doap Generate a DOAP file from a POM.
docck Documentation checker plugin.
javadoc Generate Javadoc for the project.
jxr Generate a source cross reference.
pmd Generate a PMD report.
project-info-reports Generate a standard project reports.
surefire-report Generate a report based on the results of unit tests.
IDE Description
eclipse Generate an Eclipse project file for the current project
idea Create/update an IDEA workspace for the current project
Tools Description
ant Generate an Ant build file for the project.
antrun Run a set of ant tasks from a phase of the build.
archetype Generate a skeleton project structure from an archetype.
assembly Build an assembly of sources and/or binaries.
dependency Dependency manipulation and analysis.
enforcer Environmental constraint checking, User Custom Rule Execution.
gpg Create signatures for the artifacts and poms.
help Get information about the working environment for the project.
invoker Run a set of Maven projects and verify the output
one A plugin for interacting with legacy Maven 1.x repositories and builds.
patch Use the gnu patch tool to apply patch files to source code.
plugin Create a Maven plugin descriptor for any Mojo's found in the source tree, to include in the JAR.
release Release the current project
remote-resources Copy remote resources to the output directory for inclusion in the artifact.
repository Plugin to help with repository-based tasks.
scm Generate a SCM for the current project.
source Build a JAR of sources for use in IDEs and distribution to the repository.


Not all plugins are released to use. In some cases it is necessary to build the plugin yourself.

Plugin Errors

If you get a message like: The PluginDescriptor for the plugin Plugin [<name>] was not found. the plugin is probaby not suited for usage in maven 2. Example are the cobertura report plugin. Try to find another version of the plugin or build your own version.



The most important reporting pkugins for Maven2 can be found at:

Plugin From Status Description
Checkstyle Apache Release Checks the code style against the project standards
Clover Alassian Release Tests the coverage of the tests with a database,
Cobertura Mojo Codehaus Release Tests the coverage of the unit tests. See Cobertura ar Sourceforge.
DOAP Apache. Release Generates a Description of a Project (DOAP) file from a POM
To generate the DOAP file use mvn -N doap:generate
Docck Apache Release Checks that a project complies with the Plugin Documentation Standard.
Javadoc Apache Release Creates javadoc. Look at the website for all the available goals (Mojo's).
Jxr Apache Release The JXR plugin produces a cross-reference of the project's sources
Pmd Apache Release Code analysis tool on your project's source code and generate a site report with its results. It also supports the separate Copy/Paste Detector tool (or CPD) distributed with PMD.
Project-info Apache Release Generate reports information about the project.
Simian Mojo Codehaus Sandbox Generates a copy/paste detection (duplicate lines) based on the Redhill Simian tool. More about Maven sandbox
Sonar Mojo Codehaus Release Sonar is an open platform to manage code quality. As such, it covers the 7 axes of (source) code quality: Architecture Design, Comments, Coding Rules, Potential Bugs, Complexity, Unit Test, Duplications. See Nemo for an on line insight of Open Source Projects.
See Sonar Documentation for more in depth information and documentation.
Surefire Apache Release Parses the generated TEST-*.xml files under ${basedir}/target/surefire-reports and renders them to DOXIA which creates the web interface version of the test results.

Documentation & Guides

See also


  • Maven See also on this wiki contains more links.
  • Collection of plugins at Mojo Codehaus, The Mojo project is a collection of plugins for Maven 2.
    Plugins are currently being published to the Codehaus repository. Previous releases have also been published on the Maven Central repository. Snapshots are available on request through the user mailing list or by emailing the maintainer. Each plugin has a list of people involved in creating or supporting it.
  • Nemo Sonar Source, Sonar website containing the Apache,
  • SonaType, Sonatype is transforming software development. The company was founded by Jason van Zyl, the creator of Apache Maven, to deliver innovative solutions that increase developer productivity, improve project management and reduce business risk. Sonatype’s value-added Maven products and services help organizations optimize their development process and create a standard development infrastructure. Software development organizations rely on Sonatype to deliver better software faster, while adhering to internal standards and policies. Sonatype is privately held with investments from Accel Partners, Bay Partners, Hummer Winblad Venture Partners, and Morgenthaler Ventures.
  • Maven2 Eclipse, How to use Maven2 and Eclipse



  1. Apache home of Maven and Ant and of course much more.