Semantic Versioning
& Dependency Conflicts
Learn how software projects communicate compatibility through version numbers, and what happens when dependencies disagree.
What is Versioning?
Every time a library or application is released, it receives a version number: a short label that tells other developers exactly what changed. Without versioning, you would never know if an update is safe to install or if it might break your code.
The SemVer Format
Why SemVer Matters in Java
Java projects use build tools like Maven and Gradle that automatically download libraries from the internet. Those tools rely on version numbers to decide which release to fetch. If the version is wrong, your code may not compile or may crash at runtime.
implementation 'com.google.code.gson:gson:2.10.1'
The Three Numbers Explained
Version Ranges & Compatibility
Build tools can specify version ranges. For example, requesting "1.+" in Gradle means "any version in the 1.x family." All patches and minor bumps within a major version should be safe upgrades.
Breaking vs Non-Breaking Changes
| Breaking (Major) | Non-Breaking (Minor/Patch) | |
|---|---|---|
| Removing a public method | ✕ Breaks callers | N/A: don't remove |
| Adding a new method | Only if on interface clients implement | ✓ Safe addition |
| Changing return type | ✕ Breaks callers | N/A: don't change |
| Fixing a bug in logic | Only if callers depend on the bug | ✓ Patch fix |
| Adding a new class | ✓ Minor bump |
What is a Dependency Conflict?
A dependency conflict occurs when two or more libraries in your project require different versions of the same dependency. Since the JVM can only load one version of a class at runtime, the build tool must choose: and the wrong choice can cause compilation errors or runtime crashes.
The Diamond Dependency Problem
The classic shape of a dependency conflict forms a diamond: your project depends on A and B, and both A and B depend on different versions of C. This is called the diamond dependency problem and is one of the most common headaches in real-world Java projects.
How Build Tools Resolve Conflicts
How to Diagnose a Conflict
./gradlew dependencies. In Maven: mvn dependency:tree.resolutionStrategy or Maven's <dependencyManagement> to pin a specific version.Example 1: Safe Minor Bump
Your project uses Gson 2.9.0. A new release Gson 2.10.1 is published. Is it safe to upgrade?
implementation 'com.google.code.gson:gson:2.9.0'
// Updated
implementation 'com.google.code.gson:gson:2.10.1'
Example 2: Breaking Major Bump
Library A requires Jackson 2.15.0. Library B requires Jackson 3.0.0. What happens?
Example 3: Resolving the Conflict
Continuing from the previous slide, here are three strategies to resolve a major-version conflict:
Common Mistakes
2.+ or LATEST in production. Builds become unpredictable: they may work today and fail tomorrow when a new version is published.NoSuchMethodError appears at runtime, it is often a dependency conflict. Students often ignore the stack trace instead of checking the dependency tree.Summary Table
| Concept | Definition | Key Takeaway |
|---|---|---|
| MAJOR | Incompatible API changes | May break your code |
| MINOR | New features, backward-compatible | Safe to upgrade |
| PATCH | Bug fixes only | Always safe |
| Diamond Problem | Two deps need different versions of C | Check major versions |
| Maven Resolution | Nearest definition wins | May pick older version |
| Gradle Resolution | Highest version wins | May pick breaking version |
Question 1 of 5
A library's version changes from 3.2.4 to 3.3.0. What does this indicate?
Question 2 of 5
Your code works with Library X version 4.1.2. Which upgrade is most likely to break your code?
Question 3 of 5
In the diamond dependency problem, Library A needs C:1.8 and Library B needs C:1.12. Is this likely a dangerous conflict?
Question 4 of 5
How does Gradle resolve a dependency conflict by default?
Question 5 of 5
You see a NoSuchMethodError at runtime but your code compiles fine. What is the most likely cause?