
Maven Dependency Tree – How to Resolve Conflicts
Maven dependency trees can quickly become a nightmare when transitive dependencies clash, especially in large projects with multiple modules. Understanding how to analyze and resolve these conflicts is crucial for maintaining stable builds and avoiding runtime failures. This guide will walk you through practical techniques for visualizing dependency trees, identifying version conflicts, and implementing effective resolution strategies using Maven’s built-in tools and best practices.
Understanding Maven Dependency Resolution
Maven uses a nearest-wins strategy for dependency resolution, which means when multiple versions of the same artifact exist in your dependency tree, Maven selects the version that’s closest to your project root. This sounds simple in theory, but gets complex when you have deep dependency chains.
Here’s how Maven’s resolution algorithm works:
- Dependency mediation – nearest definition wins
- Dependency management – direct specification of artifact versions
- Dependency scope – system and import scopes have special behavior
- Excluded dependencies – explicitly excluded artifacts are omitted
The problem arises when different libraries require incompatible versions of the same dependency. For example, Library A needs Jackson 2.9.x while Library B requires Jackson 2.12.x for critical security fixes.
Visualizing Your Dependency Tree
Before resolving conflicts, you need to see what’s happening under the hood. Maven provides several commands to analyze your dependency structure:
mvn dependency:tree
This basic command shows your entire dependency hierarchy. For more focused analysis, use these variations:
# Show conflicts and their resolution
mvn dependency:tree -Dverbose
# Filter by specific artifact
mvn dependency:tree -Dincludes=org.springframework:*
# Output to file for analysis
mvn dependency:tree -DoutputFile=dependency-tree.txt
# Show only conflicts
mvn dependency:tree -Dverbose -Dincludes=*:* | grep "conflict"
The verbose flag reveals omitted dependencies and why they were excluded, which is essential for understanding conflict resolution.
Identifying Common Conflict Types
Most dependency conflicts fall into these categories:
Conflict Type | Description | Maven Output Indicator | Risk Level |
---|---|---|---|
Version Conflict | Same artifact, different versions | (version managed from X; omitted for conflict with Y) | Medium |
Transitive Exclusion | Dependency pulled by multiple parents | (omitted for duplicate) | Low |
Scope Mismatch | Same dependency with different scopes | (omitted for conflict with compile) | High |
Classifier Conflict | Different classifiers of same artifact | (omitted for conflict with classifier) | Medium |
Step-by-Step Conflict Resolution
Step 1: Analyze the Conflict
Run dependency analysis to identify conflicts:
mvn dependency:analyze
mvn dependency:tree -Dverbose > deps.txt
Look for lines containing “omitted for conflict” or “version managed from” in your output.
Step 2: Use Dependency Management
The most reliable approach is explicit version management in your parent POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4</version>
</dependency>
</dependencies>
</dependencyManagement>
Step 3: Strategic Exclusions
When dependency management isn’t enough, exclude problematic transitive dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.23</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
Step 4: Verify Resolution
After making changes, verify your resolution worked:
# Check effective POM
mvn help:effective-pom
# Verify no conflicts remain
mvn dependency:tree -Dverbose | grep conflict
# Test compilation and packaging
mvn clean compile test package
Real-World Examples and Use Cases
Example 1: Spring Boot and Jackson Version Mismatch
A common scenario involves Spring Boot applications where different starter dependencies pull incompatible Jackson versions:
# Problem identification
mvn dependency:tree -Dincludes=com.fasterxml.jackson.core:*
# Shows output like:
# [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.7.4:compile
# [INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.4:compile
# [INFO] +- some-legacy-lib:old-lib:jar:1.0:compile
# [INFO] | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.9.10:compile - omitted for conflict with 2.13.4)
Resolution using Spring Boot’s dependency management:
<properties>
<jackson.version>2.13.4</jackson.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Example 2: Multi-Module Project Conflicts
In multi-module projects, different modules often introduce conflicting dependencies. Here’s a practical resolution strategy:
# Parent POM dependency management
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</dependencyManagement>
Advanced Resolution Techniques
Using Maven Enforcer Plugin
Prevent conflicts before they happen with the enforcer plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>enforce-dependency-convergence</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<dependencyConvergence/>
<bannedDependencies>
<excludes>
<exclude>commons-logging:commons-logging</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Gradle vs Maven Dependency Resolution
Aspect | Maven | Gradle |
---|---|---|
Resolution Strategy | Nearest wins | Newest version wins |
Conflict Visibility | dependency:tree -Dverbose | gradle dependencies –configuration |
Version Locking | dependencyManagement | gradle.lockfile |
Exclusion Syntax | XML exclusions block | exclude group/module |
Performance Impact and Monitoring
Dependency conflicts don’t just cause build issues – they impact runtime performance and security. Here’s what to monitor:
- Build time increases due to conflict resolution
- JAR file size bloat from duplicate dependencies
- Runtime ClassLoader exceptions
- Memory overhead from loaded duplicate classes
Use these commands to measure impact:
# Check final JAR dependencies
mvn dependency:list -DoutputFile=final-deps.txt
# Analyze JAR sizes
mvn dependency:copy-dependencies -DoutputDirectory=target/deps
du -sh target/deps/
# Check for duplicate classes
mvn dependency:analyze-duplicate
Best Practices and Common Pitfalls
Best Practices
- Use BOM (Bill of Materials) imports for consistent version management
- Regularly audit dependencies with
mvn versions:display-dependency-updates
- Implement dependency convergence rules in CI/CD pipelines
- Document exclusion reasons in comments for team awareness
- Test thoroughly after resolving conflicts, especially integration tests
Common Pitfalls
- Over-excluding dependencies leading to NoClassDefFoundError at runtime
- Ignoring transitive security vulnerabilities in older versions
- Not testing exclusions across different deployment environments
- Mixing scope types inappropriately (compile vs provided vs runtime)
- Relying solely on IDE dependency resolution instead of command-line verification
Integration with Deployment Infrastructure
When deploying applications with resolved dependencies to production environments, consider your infrastructure requirements. Modern VPS environments need sufficient memory and storage for dependency-heavy applications, while enterprise deployments might benefit from dedicated servers that can handle multiple application instances with varying dependency requirements.
For automated dependency analysis in CI/CD pipelines, integrate these Maven commands:
# CI pipeline dependency check
mvn dependency:analyze-only dependency:tree -Dverbose
if grep -q "conflict" dependency-output.txt; then
echo "Dependency conflicts detected!"
exit 1
fi
Understanding Maven dependency resolution is essential for maintaining robust Java applications. By systematically analyzing conflicts, implementing proper exclusions, and following best practices, you can ensure your projects build reliably and run securely across all environments. Regular dependency audits and proactive conflict prevention will save countless hours of debugging and reduce security vulnerabilities in production systems.
For additional information on Maven dependency management, consult the official Maven documentation and the Maven Dependency Plugin reference.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.