Skip to content
Ameen Abozaid
JNR-002

Maven in depth

  • 8 Lessons
  • 88 min of reading
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Dependency scopes
  • transitive dependencies
  • BOMs
  • plugins
  • multi-module basics
  • reproducible builds

Learn first

88 min of reading · 3 h of practice (estimate)

Learning outcomes

  1. Choose the correct dependency scope (compile, provided, runtime, test) for a dependency.
  2. Inspect the dependency tree, explain transitive dependencies, and resolve a version conflict.
  3. Import a BOM to align versions and explain why Spring Boot uses one.
  4. Configure common plugins (compiler, surefire, failsafe) and split a project into a multi-module build.
  5. Explain what makes a build reproducible and use the Maven Wrapper.

Lessons

  1. 01Dependency scopes11 min read
  2. 02Transitive dependencies and dependency:tree11 min read
  3. 03Version conflicts and dependency management11 min read
  4. 04BOMs11 min read
  5. 05Plugins and the build lifecycle revisited11 min read
  6. 06Multi-module projects11 min read
  7. 07Reproducible builds and the Maven Wrapper11 min read
  8. 08Demo: untangling a dependency conflict with dependency:tree11 min read

Lab and exercises

Lab

JNR-002-LAB1 · Shop multi-module

Outcomes: 1–5 · Time: ~2 h Split the project into shop-core and shop-cli with a parent POM, central dependency management, and the Maven Wrapper. A version conflict is planted in the starter; diagnose it with dependency:tree and fix it. Acceptance: ./mvnw verify passes on a clean clone; no version is hard-coded in a child module; the README explains the conflict cause.

Exercises (assessment: fix a broken multi-module build and explain the cause, plus six exercises)

IDOutcomeTask
JNR-002-EX011Pick a scope for each: JUnit, Postgres JDBC driver, Servlet API (server provides it), Guava used in your code.
JNR-002-EX022Run dependency:tree on a project and name one transitive dependency and the dependency that brought it.
JNR-002-EX032Two libraries need commons-lang3 3.9 and 3.14. Which does Maven choose by default? Show two ways to control it.
JNR-002-EX043Import a BOM and add one dependency without a version. Explain why this is safer.
JNR-002-EX054Configure the compiler plugin for the Java release, and say which plugin runs *Test and which runs *IT.
JNR-002-EX064Create a parent POM with two modules, where one depends on the other. Show the build order.
JNR-002-EX075Add the wrapper, remove Maven from your PATH, and run the build. List three things that make a build reproducible.
Show solutions
  • EX01 JUnit test; JDBC driver runtime; Servlet API provided; Guava compile.
  • EX02 Example: failureaccess brought by guava. Read it from the tree indentation.
  • EX03 The nearest declaration wins; if equal distance, the first declared. Control with dependencyManagement (pin) or a direct dependency or exclusion.
  • EX04 <scope>import</scope><type>pom</type> in dependencyManagement; the version comes from the BOM, so libraries match.
  • EX05 <release> in maven-compiler-plugin; Surefire runs *Test; Failsafe runs *IT.
  • EX06 The parent lists <modules>; the dependency module builds first (Maven sorts by dependencies).
  • EX07 mvn wrapper:wrapper, then ./mvnw verify. Reproducible: fixed versions (no ranges), wrapper-pinned Maven, same Java release.
  • All outcomes are also covered by the lab; outcome 5 is covered by quiz Q10.

Quiz

Outcomes: O1 scopes · O2 dependency tree and conflicts · O3 BOMs · O4 plugins and multi-module · O5 reproducible builds.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Which scope for JUnit?O1
  2. 2Which scope for a database driver used only at run time?O1
  3. 3Which command prints the dependency tree?O2
  4. 4A transitive dependency is one that:O2
  5. 5In a version conflict, Maven by default picks:O2
  6. 6What is a BOM?O3
  7. 7Why does Spring Boot use a BOM?O3
  8. 8Which plugin runs integration tests (*IT)?O4
  9. 9A parent POM uses packaging:O4
  10. 10The Maven Wrapper ensures:O5

Practical part

Seven exercises JNR-002-EX01 to EX07 plus the lab; for the assessment, fix a broken multi-module build and explain the cause. Pass: at least 8 of 10 quiz answers, six exercises correct, and ./mvnw verify green on a clean clone.

Common mistakes

Hard-coded versions in every module; compile scope for test libraries; ignoring dependency convergence.

Assessment

Fix a broken multi-module build and explain the cause.

Career relevance

Every Spring Boot project; dependency security (MID-053).

Type to search levels, phases, modules and lessons.