Learn Maven

Convention-driven build and dependency manager for Java projects, defined by the POM

14 lessons · 3 hours · 4 levels · covers Maven 3.9 / 4.0

Apache Maven builds Java projects from a declarative pom.xml: it resolves dependencies from Maven Central, runs a fixed lifecycle of phases (compile, test, package, install, deploy) through plugins, and defines the repository format the whole JVM ecosystem shares. Knowing it lets you build and maintain the many Java codebases, including most Spring Boot services, that use it.

Before you start

Maven builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics4 lessons · 38 min in total
2. PracticalUse it productively at work, with the usual idioms8 lessons · 1 hour in total
3. AdvancedThe less common features, performance and trade-offs11 lessons · 2 hours in total
4. ExpertInternals and the edge cases experts know14 lessons · 3 hours in total

The Maven tree

MavenThe POM and the mvn commandThe POM and themvn commandDeclaring dependencies and scopesDeclaringdependencies and…The build lifecycleThe build lifecycleTesting with Surefire and FailsafeTesting with Surefireand FailsafedependencyManagement and BOMsdependencyManag…and BOMsConfiguring pluginsConfiguring pluginsMulti-module projects and parent POMsMulti-moduleprojects and parent…Profiles, properties and settings.xmlProfiles, propertiesand settings.xml
Essentials and Practical shown (8 of 14 lessons); the full list is below. Click a lesson to read it.

All 14 lessons, in order

Getting started

  1. The POM and the mvn command · Essentials · 10 min

    Read a minimal pom.xml, understand coordinates and packaging, and run the common mvn commands.

  2. Profiles, properties and settings.xml · Practical · 10 min

    Vary the build per environment with profiles, properties and the user-level settings.xml for mirrors and credentials.

Dependencies

  1. Declaring dependencies and scopes · Essentials · 10 min

    Add libraries with dependency elements and the compile, provided, runtime, test and import scopes.

  2. dependencyManagement and BOMs · Practical · 12 min

    Centralize versions with dependencyManagement, import BOMs, and understand how managed versions apply to transitives.

  3. Transitive conflicts and exclusions · Advanced · 12 min

    Understand nearest-wins resolution, read dependency:tree output, and fix conflicts with exclusions and managed versions.

Lifecycle and plugins

  1. The build lifecycle · Essentials · 10 min

    Understand phases, how plugins' goals bind to them, and what mvn verify or mvn install actually runs.

  2. Testing with Surefire and Failsafe · Essentials · 8 min

    Run JUnit 5 unit tests with Surefire, integration tests with Failsafe, and filter or configure test runs.

  3. Configuring plugins · Practical · 10 min

    Configure plugins in the build section, bind executions to phases, and use pluginManagement for shared settings.

  4. Packaging runnable applications · Advanced · 12 min

    Build executable jars with the jar, shade or Spring Boot plugins, handle resources and manifests, and avoid shading pitfalls.

Multi-module and release

  1. Multi-module projects and parent POMs · Practical · 12 min

    Structure a build as a parent POM with modules, share configuration through inheritance, and build selected modules.

  2. Deploying and releasing artifacts · Advanced · 12 min

    Publish snapshots and releases to repositories with distributionManagement, the deploy plugin, versions plugin and release flows.

  3. Writing Maven plugins and extensions · Expert · 14 min

    Write a Mojo with annotated parameters, bind it to a phase, test it, and know when a core extension is the right tool.

  4. Build performance and reproducibility · Expert · 12 min

    Speed up Maven with parallel builds, the daemon, build cache extension and incremental compilation, and make builds reproducible.

  5. Maven 4: what changes · Expert · 10 min

    Know the Maven 4 changes: model version 4.1.0, build vs consumer POMs, subprojects, reactor improvements and the new API.