The POM is the single source of truth for a Maven build; every task starts from it and from the mvn command.
Maven describes a project in pom.xml, the Project Object Model. Every project has coordinates:
groupId: the organization or project namespace, likecom.acme.artifactId: the name of the module, likeshop-api.version:1.0.0for a release or1.1.0-SNAPSHOTfor work in progress.packaging:jar(default),war, orpomfor aggregator/parent projects.
The same coordinates identify every library you depend on. Maven follows convention over configuration: sources live in src/main/java, resources in src/main/resources, tests in src/test/java, and output goes to target/. You configure only what differs from the conventions.
Set the Java version with the maven.compiler.release property (<properties><maven.compiler.release>21</maven.compiler.release></properties>), and project.build.sourceEncoding to UTF-8.
Common commands:
mvn compile,mvn test,mvn package(buildstarget/shop-api-1.0.0.jar),mvn verify,mvn install(copies to~/.m2/repository).mvn cleandeletestarget/;mvn clean packageis the typical full build.-qquiet,-Xdebug,-eshow stack traces,-DskipTestsskip tests,-ooffline,-f other/pom.xmlanother file.
Most projects commit the Maven Wrapper (mvnw, .mvn/wrapper/) created with mvn wrapper:wrapper, so everyone uses the same Maven version; run ./mvnw instead of mvn.
Example
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.acme</groupId>
<artifactId>shop-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
<!-- src/main/java/com/acme/App.java, then:
./mvnw clean package -> target/shop-api-1.0.0-SNAPSHOT.jar
./mvnw test -q -> runs src/test/java with Surefire
java -cp target/classes com.acme.App -->Remember
- groupId:artifactId:version identify a project and every dependency
- Conventions: src/main/java, src/test/java, target/
- maven.compiler.release sets the Java version
- clean, compile, test, package, install are the everyday commands
Watch out for
- Running mvn with a different major version than teammates; commit the wrapper and use ./mvnw.