Maven Tutorial
Learn Maven step by step: 41 lessons in 11 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Maven? Learn what Apache Maven is, which build problems it solves, how convention over configuration works, and how it compares with Ant and Gradle.
- Installing Maven and the Wrapper Install a JDK and Apache Maven on Windows, macOS or Linux, set JAVA_HOME, check mvn -v, and use the Maven Wrapper so every machine builds with the same version.
- Maven in IntelliJ IDEA, Eclipse and VS Code Create a Maven project in IntelliJ IDEA or Eclipse, import an existing one, reload after POM changes, run goals from the IDE and fix the usual JDK and sync problems.
- Your First Maven Project Generate a Maven project from an archetype, read the resulting folders, build a hello-world JAR with mvn package and understand every line of the console output.
- The Standard Directory Layout Learn every folder in a Maven project: src/main/java, src/main/resources, src/test, and target. See why the convention matters and how resource filtering works.
The POM
- The POM File Understand the Maven pom.xml: the project root, modelVersion, coordinates, packaging, name and description, dependencies and the idea of an effective POM.
- Coordinates: groupId, artifactId, version Learn Maven GAV coordinates: naming rules for groupId and artifactId, how versions are ordered, SNAPSHOT versus release, and why version ranges are risky.
- Properties and Build Settings Use Maven properties and ${...} interpolation, set UTF-8 encoding and maven.compiler.release, and configure a Java 25 build that behaves the same everywhere.
- Parent POMs and the Effective POM Learn how Maven POM inheritance works: the parent element, the Super POM, relativePath, what children inherit, and how to inspect the result with help:effective-pom.
Lifecycle and Plugins
- Lifecycles and Phases Understand Maven's three lifecycles (default, clean, site), every phase from validate to deploy, and why running one phase also runs all the phases before it.
- Plugins and Goals Learn how Maven plugins and goals work: the plugin:goal syntax, default bindings per packaging, mvn compile versus compiler:compile, executions and pluginManagement.
- The Core Plugins in Practice Configure Maven's core plugins in practice: compiler (release vs source/target), resources filtering, surefire, jar, clean, install and deploy, with safe settings.
- Documents with Maven: Asciidoctor and Apache POI Generate HTML or PDF documentation from AsciiDoc with the Asciidoctor Maven plugin, create PowerPoint files with Apache POI, and run the code from Maven with exec.
- The Command Line Toolbox Learn the Maven command-line options you use daily: -D, -P, -pl, -am, -T, -o, -q, -X, -DskipTests, -rf and -ntp, and how to read logs and stack traces.
Dependencies
- Adding Dependencies Learn how the Maven dependency element works, how to find a library on Maven Central, add it to your POM, refresh your IDE and fix missing-dependency errors.
- Dependency Scopes Understand Maven dependency scopes: compile, provided, runtime, test, system and import, which classpath each one joins, and how scope changes transitively.
- Transitive Dependencies and Mediation See how Maven pulls in transitive dependencies, how nearest-wins and first-declaration pick one version, and how exclusions and optional dependencies change the graph.
- Managing Versions: dependencyManagement and BOMs Control library versions in one place with dependencyManagement, import-scope BOMs like Spring Boot and Jackson, version properties and the enforcer convergence rule.
- Diagnosing Dependency Conflicts Find and fix Maven dependency conflicts with dependency:tree -Dverbose and dependency:analyze, understand NoSuchMethodError and classpath hell, and when to shade.
Repositories
- Repositories and the Local Cache Learn how Maven repositories work: the ~/.m2 local cache, Maven Central, how a GAV becomes a file path, checksums, update policies and offline mode.
- settings.xml, Mirrors and Credentials Configure Maven per machine with settings.xml: user and global files, mirrors, proxies, server credentials, password encryption and a Nexus or Artifactory proxy.
Testing and Quality
- Running Tests with Surefire Run JUnit tests from Maven with the Surefire plugin: dependency setup, naming patterns, -Dtest filters, skipTests versus maven.test.skip, and test reports.
- Testing with JUnit and Mockito in a Maven project Add JUnit and Mockito to a Maven project with the right scopes, write unit tests with mocks, stubs, verification and captors, and run them with Surefire.
- Integration Tests with Failsafe Separate slow integration tests from unit tests with the Maven Failsafe plugin: IT naming, the verify phase, why two plugins exist, and how to run and skip them.
- Code Quality: Coverage and Static Checks Add quality gates to a Maven build: JaCoCo coverage thresholds, Checkstyle, SpotBugs, the Enforcer plugin and formatter plugins, and fail the build on violations.
Packaging and Multi-module
- Packaging: JAR, WAR and Executable Jars Choose the right Maven packaging: jar, war and pom, the MANIFEST Main-Class entry, and how Shade, Assembly and the Spring Boot plugin build a runnable fat jar.
- Multi-Module Builds and the Reactor Split a Maven project into modules: aggregator POMs, the reactor build order, inter-module dependencies, -pl and -am, and inheritance versus aggregation.
- Profiles and Environments Learn how Maven profiles switch build settings by property, JDK, OS or file, how resource filtering works per environment, and the pitfalls to avoid.
Releasing and Production
- Publishing: Install, Deploy and Maven Central Understand the difference between mvn install and mvn deploy, how to configure distributionManagement, sign artifacts with GPG and publish to Maven Central.
- Release Workflows and Reproducible Builds Automate Maven releases with the release and versions plugins, use CI-friendly ${revision} versions and make builds reproducible with outputTimestamp.
- Maven in CI and Faster Builds Run Maven on GitHub Actions, cache the local repository, build modules in parallel with -T, use mvnd and the build cache extension, and model build times.
- Writing a Simple Maven Plugin Write your own Maven plugin: the maven-plugin packaging, a Mojo class with @Mojo and @Parameter, the generated descriptor, phase binding and testing.
- Dependency Security and Supply Chain Protect a Maven build from vulnerable and malicious dependencies: OWASP dependency-check, Dependabot and Renovate, checksums, signatures and enforcer rules.
Alternatives and Migration
- Maven vs Gradle Compare Maven and Gradle: declarative XML versus scripted builds, speed, ecosystem, when to pick each, and how a pom.xml maps to a build.gradle file.
- Troubleshooting Common Maven Errors Read Maven failures like a pro: wrong Java version, missing dependencies, plugin not found, stale cache, certificate, proxy and out-of-memory errors, with fixes.
Projects
- Project: A Reusable Library Build a small Java library with Maven: tests, sources and javadoc jars, install it into your local repository, then use it from a second project.
- Project: A Multi-Module Application Build a three-module Maven application with a parent POM, managed versions, a BOM import and a runnable jar, and watch the reactor order and classpath.
- Project: A CI Pipeline for a Maven Project Set up GitHub Actions for a Maven project: build and test on every push, cache dependencies, report coverage, and release on a version tag.
Practice and Review
- Practice Exercises with Solutions Twelve graded Maven exercises on POMs, scopes, dependency mediation, profiles, versions and reactor order, with full solutions and runnable checkers.
- Maven Interview Questions Prepare for a Maven interview: lifecycle phases, dependency scopes, mediation, dependencyManagement, SNAPSHOT versions, profiles and multi-module builds, with short answers.
- Maven Cheat Sheet One-page Maven cheat sheet: everyday commands, lifecycle phases, dependency scopes, a POM skeleton, command-line flags and a troubleshooting table for common build errors.