---- POM Reference ----- Eric Redmond ----- 2008-01-02 ----- POM Reference [[1]] {{{Introduction}Introduction}} [[1]] {{{What_is_the_POM}What is the POM?}} [[2]] {{{Quick_Overview}Quick Overview}} [[2]] {{{The_Basics}The Basics}} [[1]] {{{Maven_Coordinates}Maven Coordinates}} [[2]] {{{POM_Relationships}POM Relationships}} [[1]] {{{Dependencies}Dependencies}} [[1]] {{{Exclusions}Exclusions}} [[2]] {{{Inheritance}Inheritance}} [[1]] {{{The_Super_POM}The Super POM}} [[2]] {{{Dependency_Management}Dependency Management}} [[3]] {{{Aggregation}Aggregation (or Multi-Module)}} [[1]] {{{Inheritance_v}Inheritance v. Aggregation}} [[3]] {{{Properties}Properties}} [[3]] {{{Build_Settings}Build Settings}} [[1]] {{{Build}Build}} [[1]] {{{BaseBuild_Element}The BaseBuild Element Set}} [[1]] {{{Resources}Resources}} [[2]] {{{Plugins}Plugins}} [[3]] {{{Plugin_Management}Plugin Management}} [[2]] {{{Build_Element}The Build Element Set}} [[1]] {{{Directories}Directories}} [[2]] {{{Extensions}Extensions}} [[2]] {{{Reporting}Reporting}} [[1]] {{{Report_Sets}Report Sets}} [[4]] {{{More_Project_Information}More Project Information}} [[1]] {{{Licenses}Licenses}} [[2]] {{{Organization}Organization}} [[3]] {{{Developers}Developers}} [[4]] {{{Contributors}Contributors}} [[5]] {{{Environment_Settings}Environment Settings}} [[1]] {{{Issue_Management}Issue Management}} [[2]] {{{Continuous_Integration_Management}Continuous Integration Management}} [[3]] {{{Mailing_Lists}Mailing Lists}} [[4]] {{{SCM}SCM}} [[5]] {{{Prerequisites}Prerequisites}} [[6]] {{{Repositories}Repositories}} [[7]] {{{Plugin_Repositories}Plugin Repositories}} [[8]] {{{Distribution_Management}Distribution Management}} [[1]] {{{Repository}Repository}} [[2]] {{{Site_Distribution}Site Distribution}} [[3]] {{{Relocation}Relocation}} [[9]] {{{Profiles}Profiles}} [[1]] {{{Activation}Activation}} [[2]] {{{The_BaseBuild_Element_Set}The BaseBuild Element Set <(revisited)>}} [[6]] {{{Final}Final}} [] {Introduction} * {{{http://maven.apache.org/xsd/maven-4.0.0.xsd}The POM 4.0.0 XSD}} and {{{http://maven.apache.org/ref/current/maven-model/maven.html}descriptor reference documentation}} * {What is the POM?} POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named <<>>. When in the presence of Maven folks, speaking of a project is speaking in the philosophical sense, beyond a mere collection of files containing code. A project contains configuration files, as well as the developers involved and the roles they play, the defect tracking system, the organization and licenses, the URL of where the project lives, the project's dependencies, and all of the other little pieces that come into play to give code life. It is a one-stop-shop for all things concerning the project. In fact, in the Maven world, a project need not contain any code at all, merely a <<>>. * {Quick Overview} This is a listing of the elements directly under the POM's project element. Notice that <<>> contains 4.0.0. That is currently the only supported POM version for both Maven 2 & 3, and is always required. +--------------------------+ 4.0.0 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... +--------------------------+ {The Basics} The POM contains all necessary information about a project, as well as configurations of plugins to be used during the build process. It is, effectively, the declarative manifestation of the "who", "what", and "where", while the build lifecycle is the "when" and "how". That is not to say that the POM cannot affect the flow of the lifecycle - it can. For example, by configuring the <<>>, one can effectively embed ant tasks inside of the POM. It is ultimately a declaration, however. Where as a <<>> tells ant precisely what to do when it is run (procedural), a POM states its configuration (declarative). If some external force causes the lifecycle to skip the ant plugin execution, it will not stop the plugins that are executed from doing their magic. This is unlike a <<>> file, where tasks are almost always dependant on the lines executed before it. +--------------------------+ 4.0.0 org.codehaus.mojo my-project 1.0 +--------------------------+ * {Maven Coordinates} The POM defined above is the minimum that both Maven 2 & 3 will allow. <<>> are all required fields (although, groupId and version need not be explicitly defined if they are inherited from a parent - more on inheritance later). The three fields act much like an address and timestamp in one. This marks a specific place in a repository, acting like a coordinate system for Maven projects. * <>: This is generally unique amongst an organization or a project. For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the <<>> group lives within the directory <<<$M2_REPO/org/codehaus/mojo>>>. * <>: The artifactId is generally the name that the project is known by. Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the {{{http://mojo.codehaus.org/}Codehaus Mojo}} project groupId: <<>>). It, along with the groupId, create a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, <<>> lives in <<<$M2_REPO/org/codehaus/mojo/my-project>>>. * <>: This is the last piece of the naming puzzle. <<>> denote a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the <<>> of today (version 4), or of four years ago (version 2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. <<>> version 1.0 files live in the directory structure <<<$M2_REPO/org/codehaus/mojo/my-project/1.0>>>. The three elements given above point to a specific version of a project letting Maven knows we are dealing with, and in its software lifecycle we want them. * <>: Now that we have our address structure of <<>>, there is one more standard label to give us a really complete address. That is the project's artifact type. In our case, the example POM for <<>> defined above will be packaged as a <<>>. We could make it into a <<>> by declaring a different packaging: +-----------------+ ... war ... +-----------------+ When no packaging is declared, Maven assumes the artifact is the default: <<>>. The valid types are Plexus role-hints (read more on Plexus for a explanation of roles and role-hints) of the component role <<>>. The current core packaging values are: <<>>, <<>>, <<>>, <<>>, <<>>, <<>>, <<>>, <<>>. These define the default list of goals which execute to each corresponding build lifecycle stage for a particular package structure. You will sometimes see Maven print out a project coordinate as <<>>. * <>: You may occasionally find a fifth element on the coordinate, and that is the <<>>. We will visit the classifier later, but for now it suffices to know that those kinds of projects are displayed as <<>>. * {POM Relationships} One powerful aspect of Maven is in its handling of project relationships; that includes dependencies (and transitive dependencies), inheritance, and aggregation (multi-module projects). Dependency management has a long tradition of being a complicated mess for anything but the most trivial of projects. <"Jarmageddon"> quickly ensues as the dependency tree becomes large and complicated. <"Jar Hell"> follows, where versions of dependencies on one system are not equivalent to versions as those developed with, either by the wrong version given, or conflicting versions between similarly named jars. Maven solves both problems through a common local repository from which to link projects correctly, versions and all. ** {Dependencies} The cornerstone of the POM is its dependency list. Most every project depends upon others to build and run correctly, and if all Maven does for you is manage this list for you, you have gained a lot. Maven downloads and links the dependencies for you on compilation and other goals that require them. As an added bonus, Maven brings in the dependencies of those dependencies (transitive dependencies), allowing your list to focus solely on the dependencies your project requires. +-----------------+ ... junit junit 4.0 jar test true ... ... +-----------------+ * <>, <>, <>:\ These elements are self-explanatory, and you will see them often. This trinity represents the coordinate of a specific project in time, demarcating it as a dependency of this project. You may be thinking: "This means that my project can only depend upon Maven artifacts!" The answer is, "Of course, but that's a good thing." This forces you to depend solely on dependencies that Maven can manage. There are times, unfortunately, when a project cannot be downloaded from the central Maven repository. For example, a project may depend upon a jar that has a closed-source license which prevents it from being in a central repository. There are three methods for dealing with this scenario. [[1]] Install the dependency locally using the install plugin. The method is the simplest recommended method. For example: --------------- mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar --------------- Notice that an address is still required, only this time you use the command line and the install plugin will create a POM for you with the given address. [[2]] Create your own repository and deploy it there. This is a favorite method for companies with an intranet and need to be able to keep everyone in synch. There is a Maven goal called <<>> which is similar to the <<>> goal (read the plugin's goal page for more information). [[3]] Set the dependency scope to <<>> and define a <<>>. This is not recommended, however, but leads us to explaining the following elements: [] * <>:\ The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number. As a motivation for this element, consider for example a project that offers an artifact targeting JRE 1.5 but at the same time also an artifact that still supports JRE 1.4. The first artifact could be equipped with the classifier <<>> and the second one with <<>> such that clients can choose which one to use. Another common use case for classifiers is the need to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers <<>> and <<>> are used to deploy the project source code and API docs along with the packaged class files. * <>:\ Corresponds to the dependant artifact's <<>> type. This defaults to <<>>. While it usually represents the extension on the filename of the dependency, that is not always the case. A type can be mapped to a different extension and a classifier. The type often corresponds to the packaging used, though this is also not always the case. Some examples are <<>>, <<>> and <<>>. New types can be defined by plugins that set <<>> to true, so this is not a complete list. * <>:\ This element refers to the classpath of the task at hand (compiling and runtime, testing, etc.) as well as how to limit the transitivity of a dependency. There are five scopes available: * <> - this is the default scope, used if none is specified. Compile dependencies are available in all classpaths. Furthermore, those dependencies are propagated to dependent projects. * <> - this is much like compile, but indicates you expect the JDK or a container to provide it at runtime. It is only available on the compilation and test classpath, and is not transitive. * <> - this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. * <> - this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. * <> - this scope is similar to <<>> except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. * <>:\ is used if the the dependency <<>> is <<>>. Otherwise, the build will fail if this element is set. The path must be absolute, so it is recommended to use a property to specify the machine-specific path (more on <<>> below), such as <<<$\{java.home\}/lib>>>. Since it is assumed that system scope dependencies are installed , Maven will not check the repositories for the project, but instead checks to ensure that the file exists. If not, Maven will fail the build and suggest that you download and install it manually. * <>:\ Marks optional a dependency when this project itself is a dependency. Confused? For example, imagine a project <<>> that depends upon project <<>> to compile a portion of code that may not be used at runtime, then we may have no need for project <<>> for all project. So if project <<>> adds project <<>> as its own dependency, then Maven will not need to install project <<>> at all. Symbolically, if <<<=\>>>> represents a required dependency, and <<<--\>>>> represents optional, although <<B>>> may be the case when building A <<A--\>B>>> would be the case when building <<>>. In the shortest terms, <<>> lets other projects know that, when you use this project, you do not require this dependency in order to work correctly. *** {Exclusions} Exclusions explicitly tell Maven that you don't want to include the specified project that is a dependency of this dependency (in other words, its transitive dependency). For example, the <<>> requires <<>>, and we do not wish to use it or its dependencies, then we would add it as an <<>>. +-----------------------------+ ... org.apache.maven maven-embedder 2.0 org.apache.maven maven-core ... ... +-----------------------------+ It is also sometimes useful to clip a dependency's transitive dependencies. A dependency may have incorrectly specified scopes, or dependencies that conflict with other dependencies in your project. Using wildcard excludes makes it easy to exclude all a dependency's transitive dependencies. In the case below you may be working with the maven-embedder and you want to manage the dependencies you use yourself, so you clip all the transitive dependencies: +-----------------------------+ ... org.apache.maven maven-embedder 3.1.0 * * ... ... +-----------------------------+ * <>: Exclusions contain one or more <<>> elements, each containing a <<>> and <<>> denoting a dependency to exclude. Unlike <<>>, which may or may not be installed and used, <<>> actively remove themselves from the dependency tree. ** {Inheritance} One powerful addition that Maven brings to build management is the concept of project inheritance. Although in build systems such as Ant, inheritance can certainly be simulated, Maven has gone the extra step in making project inheritance explicit to the project object model. +-----------------------------+ 4.0.0 org.codehaus.mojo my-parent 2.0 pom +-----------------------------+ The <<>> type required to be <<>> for and (multi-module) projects. These types define the goals bound to a set of lifecycle stages. For example, if packaging is <<>>, then the <<>> phase will execute the <<>> goal. If the packaging is <<>>, the goal executed will be <<>>. Now we may add values to the parent POM, which will be inherited by its children. The elements in the parent POM that are inherited by its children are: * dependencies * developers and contributors * plugin lists * reports lists * plugin executions with matching ids * plugin configuration [] +-----------------------------+ 4.0.0 org.codehaus.mojo my-parent 2.0 ../my-parent my-project +-----------------------------+ Notice the <<>> element. It is not required, but may be used as a signifier to Maven to first search the path given for this project's parent, before searching the local and then remote repositories. To see inheritance in action, just have a look at the {{{http://svn.apache.org/viewvc/maven/pom/trunk/asf/pom.xml?view=markup}ASF}} or {{{http://svn.apache.org/viewvc/maven/pom/trunk/maven/pom.xml?view=markup}Maven}} parent POM's. *** {The Super POM} Similar to the inheritance of objects in object oriented programming, POMs that extend a parent POM inherit certain values from that parent. Moreover, just as Java objects ultimately inherit from <<>>, all Project Object Models inherit from a base Super POM. The snippet below is the Super POM for Maven 3.0.4. %{snippet|id=superpom|url=http://svn.apache.org/repos/asf/maven/maven-3/tags/maven-3.0.4/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml} You can take a look at how the Super POM affects your Project Object Model by creating a minimal <<>> and executing on the command line: <<>> *** {Dependency Management} Besides inheriting certain top-level elements, parents have elements to configure values for child POMs and transitive dependencies. One of those elements is <<>>. * <>: is used by POMs to help manage dependency information across all of its children. If the <<>> project uses <<>> to define a dependency on <<>>, then POMs inheriting from this one can set their dependency giving the <<>>=<<>> and <<>>=<<>> only, then Maven will fill in the <<>> set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs. In addition, the version and scope of artifacts which are incorporated from transitive dependencies may also be controlled by specifying them in a dependency management section. ** {Aggregation} (or Multi-Module) A project with modules is known as a multimodule, or aggregator project. Modules are projects that this POM lists, and are executed as a group. An <<>> packaged project may aggregate the build of a set of projects by listing them as modules, which are relative directories to those projects. +-----------------------------+ 4.0.0 org.codehaus.mojo my-parent 2.0 pom my-project another-project +-----------------------------+ You do not need to consider the inter-module dependencies yourself when listing the modules, i.e. the ordering of the modules given by the POM is not important. Maven will topologically sort the modules such that dependencies are always build before dependent modules. To see aggregation in action, just have a look at the {{{http://svn.apache.org/viewvc/maven/maven-3/trunk/pom.xml?view=markup}Maven}} or {{{http://svn.apache.org/viewvc/maven/plugins/trunk/pom.xml?view=markup}Maven Core Plugins}} base POM's. *** A final note on {Inheritance v}. Aggregation Inheritance and aggregation create a nice dynamic to control builds through a single, high-level POM. You will often see projects that are both parents and aggregators. For example, the entire maven core runs through a single base POM {{{http://svn.apache.org/viewvc/maven/maven-3/trunk/pom.xml?view=markup}<<>>}}, so building the Maven project can be executed by a single command: <<>>. However, although both POM projects, an aggregator project and a parent project are not one in the same and should not be confused. A POM project may be inherited from - but does not necessarily have - any modules that it aggregates. Conversely, a POM project may aggregate projects that do not inherit from it. * {Properties} Properties are the last required piece in understanding POM basics. Maven properties are value placeholder, like properties in Ant. Their values are accessible anywhere within a POM by using the notation <<<$\{X\}>>>, where <<>> is the property. They come in five different styles: [[1]] <<>>: Prefixing a variable with "env." will return the shell's environment variable. For example, <<<$\{env.PATH\}>>> contains the PATH environment variable. While environment variables themselves are case-insensitive on Windows, lookup of properties is case-sensitive. In other words, while the Windows shell returns the same value for <<<%PATH%>>> and <<<%Path%>>>, Maven distinguishes between <<<$\{env.PATH\}>>> and <<<$\{env.Path\}>>>. As of Maven 2.1.0, <> for the sake of reliability. [[2]] <<>>: A dot (.) notated path in the POM will contain the corresponding element's value. For example: <<<\\1.0\\>>> is accessible via <<<$\{project.version\}>>>. [[3]] <<>>: A dot (.) notated path in the <<>> will contain the corresponding element's value. For example: <<<\\false\\>>> is accessible via <<<$\{settings.offline\}>>>. [[4]] Java System Properties: All properties accessible via <<>> are available as POM properties, such as <<<$\{java.home\}>>>. [[5]] <<>>: Set within a <<<\>>> element in the POM. The value of <<<\\value\\>>> may be used as <<<$\{someVar\}>>>. [] {Build Settings} Beyond the basics of the POM given above, there are two more elements that must be understood before claiming basic competency of the POM. They are the <<>> element, that handles things like declaring your project's directory structure and managing plugins; and the <<>> element, that largely mirrors the build element for reporting purposes. * {Build} According to the POM 4.0.0 XSD, the <<>> element is conceptually divided into two parts: there is a <<>> type which contains the set of elements common to both <<>> elements (the top-level build element under <<>> and the build element under <<>>, covered below); and there is the <<>> type, which contains the <<>> set as well as more elements for the top level definition. Let us begin with an analysis of the common elements between the two. <<>> +-----------------------+ ... ... ... +-----------------------+ ** The {BaseBuild Element} Set <<>> is exactly as it sounds: the base set of elements between the two <<>> elements in the POM. ------------------------------- install ${basedir}/target ${artifactId}-${version} filters/filter1.properties ... ------------------------------- * <>: the default goal or phase to execute if none is given. If a goal is given, it should be defined as it is in the command line (such as <<>>). The same goes for if a phase is defined (such as install). * <>: This is the directory where the build will dump its files or, in Maven parlance, the build's target. It aptly defaults to <<<$\{basedir\}/target>>>. * <>: This is the name of the bundled project when it is finally built (sans the file extension, for example: <<>>). It defaults to <<<$\{artifactId\}-$\{version\}>>>. The term "finalName" is kind of a misnomer, however, as plugins that build the bundled project have every right to ignore/modify this name (but they usually do not). For example, if the <<>> is configured to give a jar a <<>> of <<>>, then the actual jar defined above will be built as <<>>. * <>: Defines <<<*.properties>>> files that contain a list of properties that apply to resources which accept their settings (covered below). In other words, the "<<>>" pairs defined within the filter files replace <<<$\{name\}>>> strings within resources on build. The example above defines the <<>> file under the <<>> directory. Maven's default filter directory is <<<$\{basedir\}/src/main/filters/>>>. For a more comprehensive look at what filters are and what they can do, take a look at the {{{./guides/getting-started}quick start guide}}. *** {Resources} Another feature of <<>> elements is specifying where resources exist within your project. Resources are not (usually) code. They are not compiled, but are items meant to be bundled within your project or used for various other reasons, such as code generation. For example, a Plexus project requires a <<>> file (which specifies component configurations to the container) to live within the <<>> directory. Although we could just as easily place this file within <<>>, we want instead to give Plexus its own directory of <<>>. In order for the JAR plugin to bundle the resource correctly, you would specify resources similar to the following: +------------------------------------------+ ... META-INF/plexus false ${basedir}/src/main/plexus configuration.xml **/*.properties ... ... +------------------------------------------+ * <>: is a list of resource elements that each describe what and where to include files associated with this project. * <>: Specifies the directory structure to place the set of resources from a build. Target path defaults to the base directory. A commonly specified target path for resources that will be packaged in a JAR is META-INF. * <>: is <<>> or <<>>, denoting if filtering is to be enabled for this resource. Note, that filter <<<*.properties>>> files do not have to be defined for filtering to occur - resources can also use properties that are by default defined in the POM (such as $\{project.version\}), passed into the command line using the "-D" flag (for example, "<<<-Dname>>>=<<>>") or are explicitly defined by the properties element. Filter files were covered above. * <>: This element's value defines where the resources are to be found. The default directory for a build is <<<$\{basedir\}/src/main/resources>>>. * <>: A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard. * <>: The same structure as <<>>, but specifies which files to ignore. In conflicts between <<>> and <<>>, <<>> wins. * <>: The <<>> element block contains <<>> elements. Their definitions are similar to <<>> elements, but are naturally used during test phases. The one difference is that the default (Super POM defined) test resource directory for a project is <<<$\{basedir\}/src/test/resources>>>. Test resources are not deployed. *** {Plugins} +------------------------------------------+ ... org.apache.maven.plugins maven-jar-plugin 2.0 false true test ... ... +------------------------------------------+ Beyond the standard coordinate of <<>>, there are elements which configure the plugin or this builds interaction with it. * <>: <<>> or <<>>, whether or not to load extensions of this plugin. It is by default false. Extensions are covered later in this document. * <>: <<>> or <<>>, whether or not this plugin configuration should apply to POMs which inherit from this one. Default value is <<>>. * <>: This is specific to the individual plugin. Without going too in depth into the mechanics of how plugins work, suffice it to say that whatever properties that the plugin Mojo may expect (these are getters and setters in the Java Mojo bean) can be specified here. In the above example, we are setting the classifier property to test in the <<>>'s Mojo. It may be good to note that all configuration elements, wherever they are within the POM, are intended to pass values to another underlying system, such as a plugin. In other words: values within a <<>> element are never explicitly required by the POM schema, but a plugin goal has every right to require configuration values. If your POM declares a parent, it will inherit plugin configuration from either the <> or <> sections of the parent. To illustrate, consider the following fragment from a parent POM: +-----------------------------------------------+ my.group my-plugin parent-1 parent-2 parent +-----------------------------------------------+ And consider the following plugin configuration from a project that uses that parent as its parent: +-----------------------------------------------+ my.group my-plugin child-1 child +-----------------------------------------------+ The default behavior is to merge the content of the <> element according to element name. If the child POM has a particular element, that value becomes the effective value. if the child POM does not have an element, but the parent does, the parent value becomes the effective value. Note that this is purely an operation on XML; no code or configuration of the plugin itself is involved. Only the elements, not their values, are involved. Applying those rules to the example, Maven comes up with: +-----------------------------------------------+ my.group my-plugin child-1 child parent +-----------------------------------------------+ You can control how child POMs inherit configuration from parent POMs by adding attributes to the children of the <> element. The attributes are <<>> and <<>>. Use these attributes in a child POM to control how Maven combines plugin configuration from the parent with the explicit configuration in the child. Here is the child configuration with illustrations of the two attributes: +-----------------------------------------------+ child-1 child +-----------------------------------------------+ Now, the effective result is the following: +-----------------------------------------------+ parent-1 parent-2 child-1 child +-----------------------------------------------+ <> results in the concatenation of parent and child elements, in that order. <>, on the other hand, completely suppresses parent configuration. You cannot use both both <> and <> on an element; if you try, will prevail. Note that these attributes only apply to the configuration element they are declared on, and are not propagated to nested elements. That is if the content of an element from the child POM was a complex structure instead of text, its sub-elements would still be subject to the default merge strategy unless they were themselves marked with attributes. The combine.* attributes are inherited from parent to child POMs. Take care when adding those attributes a parent POM as this might affect child or grand-child POMs. * <>: Dependencies are seen a lot within the POM, and are an element under all plugins element blocks. The dependencies have the same structure and function as under that base build. The major difference in this case is that instead of applying as dependencies of the project, they now apply as dependencies of the plugin that they are under. The power of this is to alter the dependency list of a plugin, perhaps by removing an unused runtime dependency via <<>>, or by altering the version of a required dpendency. See above under <> for more information. * <>: It is important to keep in mind that a plugin may have multiple goals. Each goal may have a separate configuration, possibly even binding a plugin's goal to a different phase altogether. <<>> configure the <<>> of a plugin's goals. For example, suppose you wanted to bind the <<>> goal to the <<>> phase. We want the task to echo the build directory, as well as avoid passing on this configuration to its children (assuming it is a parent) by setting <<>> to <<>>. You would get an <<>> like this: +------------------------------------------+ ... maven-antrun-plugin 1.1 echodir run verify false Build Dir: ${project.build.directory} +------------------------------------------+ * <>: Self explanatory. It specifies this execution block between all of the others. When the phase is run, it will be shown in the form: <<<[plugin:goal {execution: id}]>>>. In the case of this example: <<<[antrun:run {execution: echodir}]>>> * <>: Like all pluralized POM elements, this contains a list of singular elements. In this case, a list of plugin <<>> which are being specified by this <<>> block. * <>: This is the phase that the list of goals will execute in. This is a very powerful option, allowing one to bind any goal to any phase in the build lifecycle, altering the default behavior of Maven. * <>: Like the <<>> element above, setting this false will supress Maven from passing this execution onto its children. This element is only meaningful to parent POMs. * <>: Same as above, but confines the configuration to this specific list of goals, rather than all goals under the plugin. *** {Plugin Management} * <>: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override <<>> definitions. [] +------------------------------------------+ ... ... org.apache.maven.plugins maven-jar-plugin 2.2 pre-process-classes compile jar pre-process ... +------------------------------------------+ If we added these specifications to the plugins element, they would apply only to a single POM. However, if we apply them under the <<>> element, then this POM that add the <<>> to the build will get the <<>> execution as well. So rather than the above mess included in every child <<>>, only the following is required: +------------------------------------------+ ... ... org.apache.maven.plugins maven-jar-plugin ... +------------------------------------------+ ** The {Build Element} Set The <<>> type in the XSD denotes those elements that are available only for the "project build". Despite the number of extra elements (six), there are really only two groups of elements that project build contains that are missing from the profile build: directories and extensions. *** {Directories} The set of directory elements live in the parent build element, which set various directory structures for the POM as a whole. Since they do not exist in profile builds, these cannot be altered by profiles. +------------------------------------------+ ... ${basedir}/src/main/java ${basedir}/src/main/scripts ${basedir}/src/test/java ${basedir}/target/classes ${basedir}/target/test-classes ... +------------------------------------------+ If the values of a <<<*Directory>>> element above is set as an absolute path (when their properties are expanded) then that directory is used. Otherwise, it is relative to the base build directory: <<<$\{basedir\}>>>. *** {Extensions} Extensions are a list of artifacts that are to be used in this build. They will be included in the running build's classpath. They can enable extensions to the build process (such as add an ftp provider for the Wagon transport mechanism), as well as make plugins active which make changes to the build lifecycle. In short, extensions are artifacts that activated during build. The extensions do not have to actually do anything nor contain a Mojo. For this reason, extensions are excellent for specifying one out of multiple implementations of a common plugin interface. +------------------------------------------+ ... ... org.apache.maven.wagon wagon-ftp 1.0-alpha-3 ... +------------------------------------------+ * {Reporting} Reporting contains the elements that correspond specifically for the <<>> generation phase. Certain Maven plugins can generate reports defined and configured under the reporting element, for example: generating Javadoc reports. Much like the build element's ability to configure plugins, reporting commands the same ability. The glaring difference is that rather than fine-grained control of plug-in goals within the executions block, reporting configures goals within <<>> elements. And the subtler difference is that a plugin <<>> under the <<>> element works as <<>> plugin <<>>, although the opposite is not true (a <<>> plugin <<>> does not affect a <<>> plugin). Possibly the only item under the <<>> element that would not be familiar to someone who understood the <<>> element is the Boolean <<>> element. This element signifies to the site generator to exclude reports normally generated by default. When a site is generated via the <<>> build cycle, a section is placed in the left-hand menu, chock full of reports, such as the <> report or <> list report. These report goals are generated by <<>>. Being a plugin like any other, it may also be suppressed in the following, more verbose, way, which effectively turns off project-info reports. +------------------------------------------+ ... ${basedir}/target/site maven-project-info-reports-plugin 2.0.1 ... +------------------------------------------+ The other difference is the <<>> element under <<>>. In the case of reporting, the output directory is <<<$\{basedir\}/target/site>>> by default. ** {Report Sets} It is important to keep in mind that an individual plugin may have multiple goals. Each goal may have a separate configuration. Report sets configure execution of a report plugin's goals. Does this sound familiar - deja-vu? The same thing was said about build's <<>> element with one difference: you cannot bind a report to another phase. Sorry. For example, suppose you wanted to configure the <<>> goal to link to "{{http://java.sun.com/j2se/1.5.0/docs/api/}}", but only the <<>> goal (not the goal <<>>). We would also like this configuration passed to its children, and set <<>> to true. The <<>> would resemble the following: +------------------------------------------+ ... ... sunlink javadoc true http://java.sun.com/j2se/1.5.0/docs/api/ ... +------------------------------------------+ Between build <<>> and reporting <<>>, it should be clear now as to why they exist. In the simplest sense, they drill down in configuration. The POM must have a way not only to configure plugins, but they also must configure individual goals of those plugins. That is where these elements come in, giving the POM ultimate granularity in control of its build destiny. {More Project Information} Although the above information is enough to get a firm grasp on POM authoring, there are far more elements to make developer's live easier. Many of these elements are related to site generation, but like all POM declarations, they may be used for anything, depending upon how certain plugins use it. The following are the simplest elements: * <>: Projects tend to have conversational names, beyond the <<>>. The Sun engineers did not refer to their project as "java-1.5", but rather just called it "Tiger". Here is where to set that value. * <>: Description of a project is always good. Although this should not replace formal documentation, a quick comment to any readers of the POM is always helpful. * <>: The URL, like the name, is not required. This is a nice gesture for projects users, however, so that they know where the project lives. * <>: This is another good documentation point. It will at least help you remember where you have spent the last few years of your life. * {Licenses} +-------------------------+ Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo A business-friendly OSS license +-------------------------+ Licenses are legal documents defining how and when a project (or parts of a project) may be used. Note that a project should list only licenses that may apply directly to this project, and not list licenses that apply to this project's dependencies. Maven currently does little with these documents other than displays them on generated sites. However, there is talk of flexing for different types of licenses, forcing users to accept license agreements for certain types of (non open source) projects. * <>, <> and <>: are self explanatory, and have been encountered before in other capacities. The fourth license element is: * <>: This describes how the project may be legally distributed. The two stated methods are repo (they may be downloaded from a Maven repository) or manual (they must be manually installed). * {Organization} Most projects are run by some sort of organization (business, private group, etc.). Here is where the most basic information is set. +-------------------------+ ... Codehaus Mojo http://mojo.codehaus.org +-------------------------+ * {Developers} All projects consist of files that were created, at some time, by a person. Like the other systems that surround a project, so to do the people involved with a project have a stake in the project. Developers are presumably members of the project's core development. Note that, although an organization may have many developers (programmers) as members, it is not good form to list them all as developers, but only those who are immediately responsible for the code. A good rule of thumb is, if the person should not be contacted about the project, they need not be listed here. +-------------------------+ ... eric Eric eredmond@codehaus.org http://eric.propellors.net Codehaus http://mojo.codehaus.org architect developer -6 http://tinyurl.com/prv4t ... +-------------------------+ * <>, <>, <>: These corrospond to the developer's ID (presumably some unique ID across an organization), the developer's name and email address. * <>, <>: As you probably guessed, these are the developer's organization name and it's URL, respectively. * <>: A <<>> should specify the standard actions that the person is responsible for. Like a single person can wear many hats, a single person can take on multiple <<>>. * <>: A numerical offset in hours from GMT where the developer lives or a valid {{{http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/i18n/client/constants/TimeZoneConstants.html}time zone id}} like "America/Montreal" (UTC-05:00) or "Europe/Paris" (UTC+01:00). * <>: This element is where any other properties about the person goes. For example, a link to a personal image or an instant messenger handle. Different plugins may use these properties, or they may simply be for other developers who read the POM. * {Contributors} Contributors are like developers yet play an ancillary role in a project's lifecycle. Perhaps the contributor sent in a bug fix, or added some important documentation. A healthy open source project will likely have more contributors than developers. +-------------------------+ ... Noelle some.name@gmail.com http://noellemarie.com Noelle Marie http://noellemarie.com tester America/Vancouver some.name@gmail.com ... +-------------------------+ Contributors contain the same set of elements than developers sans the <<>> element. {Environment Settings} * {Issue Management} This defines the defect tracking system (, , , etc) used. Although there is nothing stopping a plugin from using this information for something, its primarily used for generating project documentation. +-------------------------+ ... Bugzilla http://127.0.0.1/bugzilla/ ... +-------------------------+ * {Continuous Integration Management} Continuous integration build systems based upon triggers or timings (such as, hourly or daily) have grown in favor over manual builds in the past few years. As build systems have become more standardized, so have the systems that run the trigger those builds. Although the majority of the configuration is up to the specific program used (Continuum, Cruise Control, etc.), there are a few configurations which may take place within the POM. Maven has captured a few of the recurring settings within the set of notifier elements. A notifier is the manner in which people are notified of certain build statuses. In the following example, this POM is setting a notifier of type <<>> (meaning email), and configuring the email address to use on the specified triggers <<>>, <<>>, and not <<>> or <<>>. +-------------------------+ ... continuum http://127.0.0.1:8080/continuum mail true true false false
continuum@127.0.0.1
...
+-------------------------+ * {Mailing Lists} Mailing lists are a great tool for keeping in touch with people about a project. Most mailing lists are for developers and users. +-------------------------+ ... User List user-subscribe@127.0.0.1 user-unsubscribe@127.0.0.1 user@127.0.0.1 http://127.0.0.1/user/ http://base.google.com/base/1/127.0.0.1 ... +-------------------------+ * <>, <>: There elements specify the email addresses which are used for performing the relative actions To subscribe to the user list above, a user would send an email to user-subscribe@127.0.0.1. * <>: This element specifies the url of the archive of old mailing list emails, if one exists. If there are mirrored archives, they can be specified under otherArchives. * <>: The email address which one would use in order to post to the mailing list. Note that not all mailing lists have the ability to post to (such as a build failure list). * {SCM} SCM (Software Configuration Management, also called Source Code/Control Management or, succinctly, version control) is an integral part of any healthy project. If your Maven project uses an SCM system (it does, doesn't it?) then here is where you would place that information into the POM. +-------------------------+ ... scm:svn:http://127.0.0.1/svn/my-project scm:svn:https://127.0.0.1/svn/my-project HEAD http://127.0.0.1/websvn/my-project ... +-------------------------+ * <>, <>: The two connection elements convey to how one is to connect to the version control system through Maven. Where connection requires read access for Maven to be able to find the source code (for example, an update), developerConnection requires a connection that will give write access. The Maven project has spawned another project named Maven SCM, which creates a common API for any SCMs that wish to implement it. The most popular are CVS and Subversion, however, there is a growing list of other supported {{{/scm/scms-overview.html}SCMs}}. All SCM connections are made through a common URL structure. ----------- scm:[provider]:[provider_specific] ----------- Where provider is the type of SCM system. For example, connecting to a CVS repository may look like this: ----------- scm:cvs:pserver:127.0.0.1:/cvs/root:my-project ----------- * <>: Specifies the tag that this project lives under. HEAD (meaning, the SCM root) should be the default. * <>: A publicly browsable repository. For example, via ViewCVS. * {Prerequisites} The POM may have certain prerequisites in order to execute correctly. For example, perhaps there was a fix in Maven 2.0.3 that you need in order to deploy using sftp. Here is where you give the prerequisites to building. If these are not met, Maven will fail the build before even starting. The only element that exists as a prerequisite in POM 4.0 is the maven element, which takes a minimum version number. +-------------------------+ ... 2.0.6 ... +-------------------------+ * {Repositories} Repositories are collections of artifacts which adhere to the Maven repository directory layout. In order to be a Maven repository artifact, a POM file must live within the structure <<<$BASE_REPO/groupId/artifactId/version/artifactId-version.pom>>>. <<<$BASE_REPO>>> can be local (file structure) or remote (base URL); the remaining layout will be the same. Repositories exist as a place to collect and store artifacts. Whenever a project has a dependency upon an artifact, Maven will first attempt to use a local copy of the specified artifact. If that artifact does not exist in the local repository, it will then attempt to download from a remote repository. The repository elements within a POM specify those alternate repositories to search. The repository is one of the most powerful features of the Maven community. The default central Maven repository lives on {{http://repo.maven.apache.org/maven2/}}. Another source for artifacts not yet in iBiblio is the Codehaus snapshots repo. +-------------------------+ ... false always warn true never fail codehausSnapshots Codehaus Snapshots http://snapshots.maven.codehaus.org/maven2 default ... ... +-------------------------+ * <>, <>: These are the policies for each type of artifact, Release or snapshot. With these two sets, a POM has the power to alter the policies for each type independent of the other within a single repository. For example, one may decide to enable only snapshot downloads, possibly for development purposes. * <>: <<>> or <<>> for whether this repository is enabled for the respective type (<<>> or <<>>). * <>: This element specifies how often updates should attempt to occur. Maven will compare the local POM's timestamp (stored in a repository's maven-metadata file) to the remote. The choices are: <<>>, <<>> (default), <<>> (where X is an integer in minutes) or <<>>. * <>: When Maven deploys files to the repository, it also deploys corresponding checksum files. Your options are to <<>>, <<>>, or <<>> on missing or incorrect checksums. * <>: In the above description of repositories, it was mentioned that they all follow a common layout. This is mostly correct. The layout introduced with Maven 2 is the default layout for repositories used by Maven both 2 & 3; however, Maven 1.x had a different layout. Use this element to specify which if it is <<>> or <<>>. * {Plugin Repositories} Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of plugins that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the <<>> element block is similar to the repositories element. The <<>> elements each specify a remote location of where Maven can find new plugins. * {Distribution Management} Distribution management acts precisely as it sounds: it manages the distribution of the artifact and supporting files generated throughout the build process. Starting with the last elements first: +-------------------------+ ... ... http://mojo.codehaus.org/my-project deployed ... +-------------------------+ * <>: is the url of the repository from whence another POM may point to in order to grab this POM's artifact. In the simplest terms, we told the POM how to upload it (through repository/url), but from where can the public download it? This element answers that question. * <>: Warning! Like a baby bird in a nest, the status should never be touched by human hands! The reason for this is that Maven will set the status of the project when it is transported out to the repository. Its valid types are as follows. * <>: No special status. This is the default for a POM. * <>: The manager of the repository converted this POM from an earlier version to Maven 2. * <>: This could just as easily have been called synched. This means that this artifact has been synched with a partner repository. * <>: By far the most common status, meaning that this artifact was deployed from a Maven 2 or 3 instance. This is what you get when you manually deploy using the command-line deploy phase. * <>: This project has been verified, and should be considered finalized. ** {Repository} Where as the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined. +-------------------------+ ... false corp1 Corporate Repository scp://repo/maven2 default true propSnap Propellors Snapshots sftp://propellers.net/maven legacy ... ... +-------------------------+ * <>, <>: The <<>> is used to uniquely identify this repository amongst many, and the <<>> is a human readable form. * <>: The unique version takes a <<>> or <<>> value to denote whether artifacts deployed to this repository should get a uniquely generated version number, or use the version number defined as part of the address. * <>: This is the core of the repository element. It specifies both the location and the transport protocol to be used to transfer a built artifact (and POM file, and checksum data) to the repository. * <>: These are the same types and purpose as the layout element defined in the repository element. They are <<>> and <<>>. ** {Site Distribution} More than distribution to the repositories, <<>> is responsible for defining how to deploy the project's site and documentation. +-------------------------+ ... ... mojo.website Mojo Website scp://beaver.codehaus.org/home/projects/mojo/public_html/ ... ... +-------------------------+ * <>, <>, <>: These elements are similar to their counterparts above in the <<>> <<>> element. ** {Relocation} +-------------------------+ ... ... org.apache my-project 1.0 We have moved the Project under Apache ... ... +-------------------------+ Projects are not static; they are living things (or dying things, as the case may be). A common thing that happens as projects grow, is that they are forced to move to more suitable quarters. For example, when your next wildly successful open source project moves under the Apache umbrella, it would be good to give your users as heads-up that the project is being renamed to <<>>. Besides specifying the new address, it is also good form to provide a message explaining why. * {Profiles} A new feature of the POM 4.0 is the ability of a project to change settings depending on the environment where it is being built. A <<>> element contains both an optional activation (a profile trigger) and the set of changes to be made to the POM if that profile has been activated. For example, a project built for a test environment may point to a different database than that of the final deployment. Or dependencies may be pulled from different repositories based upon the JDK version used. The elements of profiles are as follows: +-------------------------+ ... test ... ... ... ... ... ... ... ... ... +-------------------------+ ** {Activation} Activations are the key of a profile. The power of a profile comes from its ability to modify the basic POM only under certain circumstances. Those circumstances are specified via an <<>> element. +-------------------------+ ... test false 1.5 Windows XP Windows x86 5.1.2600 sparrow-type African ${basedir}/file2.properties ${basedir}/file1.properties ... +-------------------------+ Activation occurs when one or more of the specified criteria have been met. When the first positive result is encountered, processing stops and the profile is marked as active. * <>: <<>> has a built in, Java-centric check in the <<>> element. This will activate if the test is run under a jdk version number that matches the prefix given. In the above example, <<<1.5.0_06>>> will match. Ranges are also supported as of Maven 2.1. See the {{{http://maven.apache.org/enforcer/enforcer-rules/versionRanges.html} maven-enforcer-plugin}} for more details about supported ranges. * <>: The <<>> element can define some operating system specific properties shown above. See the maven-enforcer-plugins {{{http://maven.apache.org/enforcer/enforcer-rules/requireOS.html}RequireOS Rule}} for more details about OS values. * <>: The <<>> will activate if Maven detects a property (a value which can be dereferenced within the POM by <<<$\{name\}>>>) of the corresponding <<>> pair. * <>: Finally, a given filename may activate the <<>> by the <<>> of a file, or if it is <<>>. <>: interpolation for this element is limited to <<<$\{basedir\}>>>, System properties and request properties. [] The <<>> element is not the only way that a <<>> may be activated. The <<>> file's <<>> element may contain the profile's <<>>. They may also be activated explicitly through the command line via a comma separated list after the <<<-P>>> flag (e.g. <<<-P codecoverage>>>). <<>>. ------- mvn help:active-profiles ------- ** {The BaseBuild Element Set} <(revisited)> As mentioned above, the reason for the two types of build elements reside in the fact that it does not make sense for a profile to configure build directories or extensions as it does in the top level of the POM. Reguardless of in which environment the project is built, some values will remain constant, such as the directory structure of the source code. {Final} The Maven POM is big. However, its size is also a testament to its versatility. The ability to abstract all of the aspects of a project into a single artifact is powerful, to say the least. Gone are the days of dozens of disparate build scripts and scattered documentation concerning each individual project. Along with Maven's other stars that make up the Maven galaxy - a well defined build lifecycle, easy to write and maintain plugins, centralized repositories, system-wide and user-based configurations, as well as the increasing number of tools to make developers' jobs easier to maintain complex projects - the POM is the large, but bright, center. ====================== Aspects of this guide were originally published in the {{{http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html}Maven 2 Pom Demystified}}.