Maven is a tool that can now be used for building and managing any Java-based project.
Maven provides tools to:
A manual build process, or even a build process created with the ANT tool, is extensive, repetitive, and not very exciting.
With Maven, developers do not have to mention each and every configuration detail; Maven provides the default behaviour for projects.
Maven defines a standard directory structure so that every developer will be immediately familiar with every Maven project.
main/java - Application/Library sources
main/resources - Application/Library resources
test/java - Test sources
test/resources - Test resources
target - Build output
POM is an XML file, and it's a fundamental unit of work in Maven, because it contains various informations and configuration details about the project.
Some configurations details include:
Extensible Markup Language (XML) is a markup language (i.e., a language that uses tags) that defines a set rules for encoding documents in a format that is readable by both machines and human beings.
XML was designed to store and transport data.
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Karl</to>
<from>Laura</from>
<heading>Reminder</heading>
<body>Don't forget our meeting this weekend!</body>
</note>
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>academy.mindswap</groupId>
<artifactId>my-first-maven-project</artifactId>
<version>1.0.0</version>
</project>
Every information that isn't explicitly specified by the developer, is inherited by from the Super POM.
A well-defined sequence of phases, which define the order in which the goals are to be executed.
A goal is a specific task which contributes to the building and managing of a project; it may be bound to zero or more build phases.
We can add goals to phases by configuring the plugins in our project.
// Execute all phases up to package
$ mvn package
Tasks on Maven are executed by plugins. A plugin generally provides a set of goals.
Maven plugins are generally used to:
// Executing a Maven goal
mvn [plugin-name]:[goal-name]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
// Executing the compile goal
mvn compiler:compile
In the POM file, we can also specify what external libraries the project depends on, and Maven will download them.
<!--EXAMPLE DEPENDENCY-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.4.4</version>
</dependency>
But how can Maven know all of this?
Plugins and dependencies are loaded from remote repositories when needed.
Downloaded software is saved in a local repository for use by all maven projects.
Environment Setup
Project Setup