Skip to content

Maven

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. (source)

Convention over configuration

Convention over configuration attempts to decrease the number of decisions that a developer using the framework is required to make without necessarily losing flexibility. Maven accomplishes this through a prescriptive build lifeycle and a defined pom.xml instructions file, making it very easy to understand what the build.

Build Lifecyle

Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artifact (project) is clearly defined. (source)

Step Description
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
package take the compiled code and package it in its distributable format (e.g. a JAR)
verify run any checks on results of integration tests to ensure quality criteria are met
install install the package into the local repository, for use as a dependency in other projects locally
deploy done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

POM

The POM "Project Object Model" file is an XML representation of a Maven project held in a pom.xml file. The POM contains all necessary information about a project, as well as configurations of plugins to be used during the build process. It is the declarative manifestation of the "who", "what", and "where", while the build lifecycle is the "when" and "how.

<project> 
  <!-- The Basics -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
  <dependencies>...</dependencies>
  <parent>...</parent>
  <dependencyManagement>...</dependencyManagement>
  <properties>...</properties>

  <!-- Build Settings -->
  <build>...</build>
  <reporting>...</reporting>
</project>

Best practices

  • Applications should be built only with using ~/.m2/settings.xml
  • All <dependency> references in the pom.xml should point to the artifact storage (no local dependencies or public repositories).
  • Inherit common properties across a team, line of business, or organization using the <parent> tag
  • Artifacts should mirror a public repository (e.g. Maven Central)