If we ask software developers what Maven is, the majority will probably respond that Maven is a build tool. We can't say they are wrong, but this definition is not complete. If we want to be more precise, we should say that Maven is a project management tool that provides build and distribution functionalities, code generation, and communication features. Above all, Maven provides an advanced dependency management system that is able to retrieve transitive dependencies and download them from both local and remote repositories.
Maven is built with a plugin-based architecture; the core architecture provides a set of features that can be extended through a set of official or custom plugins downloadable from repositories.
Maven comes with the convention over configuration philosophy. The origin of this philosophy resides in the idea that accepting conventions resulting from a set of past experiences leads to advantages such as saving time, reuse, and maintenance simplification. Maven pursues this philosophy through the use of defaults, which means that unnecessary configurations should be avoided; a project should just work.
While the use of defaults is a powerful concept, users might want to customize some behavior. Maven meets the users' needs by allowing the customization of almost all defaults.
In this chapter, we will:
In this paragraph, we will explore some of Maven's core concepts through a simple example. Maven defines project configurations through a Project Object Model (POM), which is stored in a file named pom.xml
.
The following example of pom.xml
defines a simple project. Such a simple POM file is capable of compiling and building the project without the need to specify any additional information:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- Project coordinates --> <groupId>com.mycompany.projects</groupId> <artifactId>my-first-maven-project</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>My First Maven Project!</name> </project>
Reading the example POM file, the following concepts emerge:
pom.xml
file related to each submodule to manage each module's peculiarities.groupId
, artifactId
, and version
. Project coordinates are fundamental since they allow Maven to correctly manage modules and plugins.