01 / 21
1.2.3

Semantic Versioning
& Dependency Conflicts

Learn how software projects communicate compatibility through version numbers, and what happens when dependencies disagree.

Programming Java

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.

Library
Reusable code packaged for others (e.g., Gson, JUnit)
Dependency
A library your project requires to compile or run
Version
A label that communicates the scope of changes

The SemVer Format

2.5.1 MAJOR Breaking changes MINOR New features, backward-compatible PATCH Bug fixes only

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.

// Gradle dependency declaration
implementation 'com.google.code.gson:gson:2.10.1'

The Three Numbers Explained

1
MAJOR: incremented when you make incompatible API changes. Old code that depended on the previous major version may break.
2
MINOR: incremented when you add new functionality in a backward-compatible way. Old code still works, but new features are available.
3
PATCH: incremented for backward-compatible bug fixes. No new features, just corrections to existing behavior.

Version Ranges & Compatibility

1.0.0 1.0.1 1.1.0 1.2.0 2.0.0 2.1.0 Compatible with 1.x Breaking! Compatible with 2.x Initial Patch Minor Minor Major Minor

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.

Your App Library A Library B needs 1.4 needs 2.0 Shared Dependency ✕ CONFLICT: 1.4 vs 2.0

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.

App A B C ??? C:1.4 C:2.0

How Build Tools Resolve Conflicts

Maven
Nearest definition wins: the version declared closest to your project in the dependency tree is selected.
Gradle
Highest version wins: Gradle picks the newest version, assuming backward compatibility.

How to Diagnose a Conflict

1
Run the dependency tree command. In Gradle: ./gradlew dependencies. In Maven: mvn dependency:tree.
2
Look for version mismatches. Find the same library appearing with multiple version numbers in the tree output.
3
Check the MAJOR version. If both sides want the same major version, the conflict is usually safe. Different major versions signal danger.
4
Force a resolution. Use Gradle's resolutionStrategy or Maven's <dependencyManagement> to pin a specific version.
5
Test thoroughly. Run your test suite to verify that all libraries still work with the chosen 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?

// Current
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?

Library A Library B Jackson ??? 2.15.0 3.0.0

Example 3: Resolving the Conflict

Continuing from the previous slide, here are three strategies to resolve a major-version conflict:

1
Upgrade Library A to a newer version that supports Jackson 3.x. This is the cleanest solution if available.
2
Downgrade Library B to a version that still uses Jackson 2.x. This is a fallback if option 1 is not possible.
3
Shade/relocate one copy of Jackson using a Gradle shadow plugin. This bundles a private copy of the library under a different package name, avoiding the clash entirely.

Common Mistakes

✕ Ignoring Major Bumps
Assuming version 2.x to 3.x is "just a number." Major bumps mean breaking changes: always check the changelog.
✕ Using Dynamic Versions
Writing 2.+ or LATEST in production. Builds become unpredictable: they may work today and fail tomorrow when a new version is published.
✕ Not Reading Error Messages
When a 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?