|
| 1 | +# Maven Issues Demonstration |
| 2 | + |
| 3 | +This repository demonstrates the most common Maven issues with working examples and fixes. |
| 4 | + |
| 5 | +## Issues Covered |
| 6 | + |
| 7 | +### 1. [Wrong Scopes](issues/issue1-wrong-scopes/) |
| 8 | +- Test libraries in production JARs |
| 9 | +- Server-provided libraries included |
| 10 | +- Runtime dependencies at compile time |
| 11 | +- **Examples**: JUnit as compile, Servlet API missing provided scope |
| 12 | + |
| 13 | +### 2. [Wrong Dependency Management](issues/issue2-dependency-management/) |
| 14 | +- Missing `<dependencyManagement>` section |
| 15 | +- Version conflicts between related libraries |
| 16 | +- Inconsistent versions across modules |
| 17 | +- **Examples**: Mixed Spring versions, missing SLF4J version |
| 18 | + |
| 19 | +### 3. [Transitive Dependency Conflicts](issues/issue3-transitive-conflicts/) |
| 20 | +- Different libraries bringing conflicting versions |
| 21 | +- Runtime ClassNotFoundException errors |
| 22 | +- API breaking changes |
| 23 | +- **Examples**: SLF4J 1.7 vs 2.0, Guava version conflicts |
| 24 | + |
| 25 | +### 5. [Duplicate Dependencies](issues/issue5-duplicate-deps/) |
| 26 | +- Same artifact with different versions |
| 27 | +- Multiple libraries doing same thing |
| 28 | +- Bloated classpath and JAR size |
| 29 | +- **Examples**: Multiple JSON libraries, logging implementations |
| 30 | + |
| 31 | +### 6. [Plugin Version Management](issues/issue6-plugin-versions/) |
| 32 | +- Missing plugin versions (uses Maven defaults) |
| 33 | +- Outdated plugin versions |
| 34 | +- Inconsistent behavior across environments |
| 35 | +- **Examples**: Compiler plugin without version, old JAR plugin |
| 36 | + |
| 37 | +### 8. [Circular Dependencies](issues/issue8-circular-deps/) |
| 38 | +- Modules depending on each other in circles |
| 39 | +- Build failures and compilation loops |
| 40 | +- Architecture problems |
| 41 | +- **Examples**: Module A ↔ Module B dependency cycle |
| 42 | + |
| 43 | +### 11. [Parent POM Issues](issues/issue11-parent-pom/) |
| 44 | +- Direct dependencies forcing inheritance |
| 45 | +- Missing dependency/plugin management |
| 46 | +- Version conflicts between parent/children |
| 47 | +- **Examples**: Forced Spring inheritance, hardcoded Java 8 |
| 48 | + |
| 49 | +### 12. [Multi-module Coordination](issues/issue12-multi-module/) |
| 50 | +- Wrong module build order |
| 51 | +- Version drift between sibling modules |
| 52 | +- Hardcoded inter-module versions |
| 53 | +- **Examples**: Dependencies built before their dependencies |
| 54 | + |
| 55 | +## How to Use |
| 56 | + |
| 57 | +Each issue directory contains: |
| 58 | +- `pom.xml` - Problematic configuration |
| 59 | +- `pom-fixed.xml` or `fixed/` - Correct solution |
| 60 | +- `README.md` - Detailed explanation and commands |
| 61 | + |
| 62 | +### Running Examples |
| 63 | + |
| 64 | +```bash |
| 65 | +# Try to build the problematic examples (they will fail/conflict) |
| 66 | +cd issues/issue1-wrong-scopes && mvn clean compile |
| 67 | + |
| 68 | +# Build the fixed versions (they work correctly) |
| 69 | +cd issues/issue1-wrong-scopes/fixed && mvn clean compile |
| 70 | +``` |
| 71 | + |
| 72 | +### Useful Maven Commands for Analysis |
| 73 | + |
| 74 | +```bash |
| 75 | +# Show dependency tree |
| 76 | +mvn dependency:tree |
| 77 | + |
| 78 | +# Find conflicts |
| 79 | +mvn dependency:analyze |
| 80 | + |
| 81 | +# Check for updates |
| 82 | +mvn versions:display-dependency-updates |
| 83 | +mvn versions:display-plugin-updates |
| 84 | + |
| 85 | +# Validate configuration |
| 86 | +mvn validate |
| 87 | + |
| 88 | +# Show effective POM |
| 89 | +mvn help:effective-pom |
| 90 | +``` |
| 91 | + |
| 92 | +## Key Takeaways |
| 93 | + |
| 94 | +1. **Use Dependency Management**: Central version control without forced inheritance |
| 95 | +2. **Correct Scopes**: test, provided, runtime, compile appropriately |
| 96 | +3. **Plugin Versions**: Always specify plugin versions explicitly |
| 97 | +4. **BOM Imports**: Use framework BOMs for consistent versions |
| 98 | +5. **Multi-module Order**: Build foundation modules first |
| 99 | +6. **Avoid Circles**: Design clear dependency hierarchies |
| 100 | +7. **Version Consistency**: Use properties and `${project.version}` |
| 101 | + |
| 102 | +## Common Patterns for Fixes |
| 103 | + |
| 104 | +- Replace `<dependencies>` with `<dependencyManagement>` in parent POMs |
| 105 | +- Add `<exclusions>` to resolve transitive conflicts |
| 106 | +- Use `${project.version}` for inter-module dependencies |
| 107 | +- Import BOMs with `<type>pom</type><scope>import</scope>` |
| 108 | +- Add `<pluginManagement>` for consistent plugin versions |
| 109 | +- Extract common interfaces to break circular dependencies |
0 commit comments