Maven Notes

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.

Maven makes life of developer easy while creating reports, checks, build and testing automation setups.

Maven provides developers ways to manage following:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Release0s
  • Distribution
  • mailing list

Maven increases reusability and takes care of most of build related tasks. Apache group then developed Maven which can build multiple projects together, publish projects information, deploy projects, share JARs across several projects and help in collaboration of teams.

Maven project structure and contents are declared in an xml file, pom.xml.

Convention over Configuration

Maven uses Convention over Configuration which means developers are not required to create build process themselves. When a Maven project is created, Maven creates default project structure. Developer is only required to place files accordingly and he need not to define any configuration in pom.xml. Assuming, ${basedir} denotes the project location:

Item Default
source code ${basedir}/src/main/java
Resources ${basedir}/src/main/resources
Tests ${basedir}/src/test
Complied byte code ${basedir}/target
distributable JAR ${basedir}/target/classes

Maven – POM

POM also contains the goals and plugins. While executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal. Some of the configuration that can be specified in the POM are following:

  • project dependencies
  • plugins
  • goals
  • build profiles
  • project version
  • developers
  • mailing list

Before creating a POM, we should first decide the project group (groupId), itsname(artifactId) and its version as these attributes help in uniquely identifying the project in repository.

Example POM

<project xmlns=”″   xmlns:xsi=””   xsi:schemaLocation=””>   <modelVersion>4.0.0</modelVersion>    <groupId>com.companyname.project-group</groupId>   <artifactId>project</artifactId>   <version>1.0</version> </project>

It should be noted that there should be a single POM file for each project.

  • All POM files require theproject element and three mandatory fields: groupId, artifactId,version.
  • Projects notation in repository isgroupId:artifactId:version.
1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.91 out of 5)