Dependency mediation and reproducible builds
What you will learn
Maven resolves a dependency graph, not just the entries written in your POM. Dependency management selects versions and scopes when relevant; it does not add a library by itself. A reproducible build is one whose output can be independently recreated under defined inputs.
- Predict nearest-definition version selection and managed overrides.
- Explain BOM imports and distinguish effective POM from resolved graph.
- Design an evidence-based reproducibility check.
Prerequisite: Java packages, classpath and basic terminal compilation. Maven CLI examples are static and not executed in this batch. The project is local and fictional; use only reviewed source and approved cached dependencies.
Managed version used by app
<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> <parent> <groupId>example.bytemind</groupId> <artifactId>warehouse-parent</artifactId> <version>1.0.0</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>warehouse-app</artifactId> <dependencies> <dependency> <groupId>example.bytemind</groupId> <artifactId>warehouse-core</artifactId> </dependency> </dependencies></project>Complete child POM. Core is actually added by dependencies, with version inherited from dependencyManagement in the parent. Packaging defaults to jar. Source-reviewed, not resolved by Maven.
Mediation and managed versions
Suppose app depends on A and B; A depends on C 2.0 through another library, while B depends directly on C 1.0. With no overriding management or explicit dependency, Maven chooses the nearer C 1.0; at equal distance the first declaration wins. An explicit direct version or relevant dependency management can change the result. A BOM is a POM of managed dependencies imported through type pom and scope import within dependencyManagement. It neither adds all libraries nor manages plugin dependencies. Exclusions remove an unwanted transitive path, not necessarily every path to that artifact. Declare libraries directly if your source uses them.
Reactor and inspection
The bundled warehouse uses two child modules: core builds before app because app declares core. The app omits the version because the parent manages it. A reactor build can resolve reactor projects without publishing. help:effective-pom displays the model after inheritance and profiles, while dependency:tree reports the resolved dependency graph. Both are needed to compare assumptions with reality. Running tree on a standalone child may require reactor artifacts already available; use the approved reactor context or isolated cache. Do not confuse these reports with vulnerability scans.
Reproducibility and profiles
Pin Maven/JDK, plugins, dependency versions and repository contents; avoid dynamic versions, snapshots and mutable external inputs in release builds. Set encoding, deterministic inputs and project.build.outputTimestamp for supporting plugins. The timestamp alone does not guarantee byte-for-byte output. Profiles can deliberately change inputs: explicitly activate only reviewed profiles, record the effective POM and active profiles, build in two clean independent directories, and compare SHA-256 for identical artifacts. An equal hash proves equality of those bytes, not provenance or security. A differing hash calls for examining ZIP entries, metadata, generated content and toolchains. The bundled fixture demonstrates direct JDK JAR comparison, not Maven reproducibility.
Import a BOM
<dependencyManagement> <dependencies> <!-- Fictional BOM; must already exist in an approved repository. --> <dependency> <groupId>example.bytemind</groupId> <artifactId>warehouse-bom</artifactId> <version>1.0.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>Illustrative fragment only. The fictional BOM must already be approved and available; it cannot be resolved from these examples. An ordinary dependency still has to be declared to use its classes.
Inspect and build the reactor
# In the reviewed warehouse parent directory; approved cached plugins only.mvn -o clean verifymvn -o org.apache.maven.plugins:maven-help-plugin:3.5.2:effective-pommvn -o org.apache.maven.plugins:maven-dependency-plugin:3.8.1:tree# Linux/macOS shell; Windows uses ; instead of : in the classpath.java -cp app/target/warehouse-app-1.0.0.jar:core/target/warehouse-core-1.0.0.jar example.app.MainExpected output of the final Java invocation: remaining: 8. The direct JDK fixture tests this output with the same Java sources and resource. Maven commands, effective POM, tree and Maven-produced JARs remain untested. If cache misses occur, stop and request an approved artifact cache rather than switching on arbitrary downloads.
Explicit compatibility profile
<profiles> <profile> <id>compat17</id> <properties> maven.compiler.release>17 /maven.compiler.release> </properties> </profile></profiles>Example optional parent POM fragment. -Pcompat17 would set release 17 when added and activated. Use the actual effective POM and Java 17-compatible code to validate this choice; the profile is not active in the bundled POM.
Common mistakes
Do not assume the highest version wins, that a BOM installs every dependency, or that a successful build is reproducible. Avoid declaring repositories, profiles or plugin executions that fetch unreviewed code. Record actual resolution and compare output artifacts from clean builds.
Practice
Given app → A → X → C 2.0 and app → B → C 1.0, predict C without management. Then add a managed C 2.0 version in the root. Explain how to verify the result and which evidence is still needed before claiming reproducibility.
Use the manual practice hints; explain your reasoning before consulting the private review solution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dependency mediation and reproducible builds — knowledge check
Maven 3 model and build engineering knowledge check; source-reviewed, not Maven-executed.
Which version wins by default when one dependency path is shorter?
What does importing a BOM do?
What reports the resolved dependency graph?
Which claim follows from equal artifact hashes across two controlled builds?
What does a profile potentially change?