Apache Maven 1.x has reached its end of life, and is no longer supported. For more information, see the announcement. Users are encouraged to migrate to the current version of Apache Maven.

Basic Maven Concepts

Plugins

What are Plugins?

Read the "Plugin" definition in the glossary.

Maven plugins implement the functionality. For example, the "java" plugin does java operations such as the "compile" goal.

Plugins are installed in the local Maven repository along with the other non-plugin dependencies.

For plugin reference information, refer to the Plugins page.

Maven 1 has two types of plugins: bundled and non-bundled. See below for details on these plugin types.

Note that in Maven 2, all plugins are non-bundled.

Bundled Plugins

Bundled plugins are those that come with the Maven distribution. Users need no additional actions to use them. Refer to the Plugins List.

Non-Bundled Plugins

Non-bundled plugins are those that do not come with the Maven distribution. This is how Maven is expandable with new functionality - anyone can create a Maven plugin. Since these plugins do not ship with Maven, the user must install them into the local Maven repository.

There are three ways to make a Maven plugin visible to your project:

  1. Declare the plugin as a dependency in the project. Maven will then automatically download and install it into the local repository.

    This is typically the preferred method. The benefits of this approach are:

    • Reproducibility: The project has plugin dependencies documented in addition to jar dependencies.
    • Ease: The download and install is automatic for all users/computers.
    • Snapshots: When the version is a SNAPSHOT, Maven always checks for newer versions.
    For example:
    <dependency>
      <groupId>maven-plugins</groupId>
      <artifactId>maven-findbugs-plugin</artifactId>
      <version>1.3</version>
      <type>plugin</type>
    </dependency>
    

    Note that this method does not install the plugin into Maven's plugin directory, which means that the plugin will only be usable by the project declaring it as dependency. In order to permanently install a plugin and make it visible to all your projects, you should use one of the following methods.

  2. Use the "plugin:download" goal to download the plugin and install it into Maven's plugin directory. For example:
    maven plugin:download -DgroupId=maven-plugins -DartifactId=maven-findbugs-plugin -Dversion=1.3
  3. Alternatively to the above, you may just manually download and install the plugin.

Refer to the non-bundled plugins in the list on the Plugins page.

Goals

Read the "Goal" definition in the glossary.

Ant users run custom created "targets", Maven users run goals. Usually, one runs pre-defined Maven goals (the bundled or non-bundled plugins have the goals), but sometimes users create their own goals in either a new plugin or in the maven.xml file.

For example,

maven java:compile

compiles the Java source.

Note that you can run multiple goals one after the other in the same invocation of Maven. For example,

maven faq xdoc

runs the faq plugin followed by the xdoc plugin.

Note that some plugin goals cause other plugin goals to run first. For example, running

maven jar

causes these goals to run in this order:

  1. java:compile
  2. test:test
  3. jar:jar

Refer to the Getting Started and Using Maven pages for more info.

project.xml

The project.xml file is the "POM" - project object model. It contains the configuration information for the project.

Refer to the Project Descriptor on the Reference page for its info.

Refer to th Project Inheritence section in Customising Maven for more info.

project.properties

Properties for the project are set in this file. When a plugin lists customization properties, this is the file to put them in.

When extending from another POM, this file is inherited too.

In addition to plugin properties, the Maven core itself has many properties.

Refer to the Properties Reference on the Reference page and the Extending the Build with Properties section in Customising Maven for more info.

maven.xml

Note, it is recommended to limit use of this file. The maven.xml file can contain processing customization. This includes complete custom goals and adding to the lifecycle of another plugin.

Refer to the Scripting section, Customising Maven and Maven Jelly Tag Libraries for more info.

One of the best ways to understand maven.xml is to look at ones in existing Maven projects, including those in Maven source.

Note that Maven 2 does not have this file. Instead, the plugins and the POM has all processing and configuration.