Quick revision
The short answer
It depends first on packages. If the two major versions use different package names, as Jackson 2 (com.fasterxml.jackson) and Jackson 3 (tools.jackson) do, both can sit on the classpath and each library uses its own. If they share package names, only one copy can win, so we upgrade the older consumer (the cleanest fix), shade and relocate the dependency inside one library, or, only when nothing else works, isolate it in a separate class loader or process. Longer term, we ask library owners not to expose third-party types in their public APIs, which is what makes these conflicts hard.
What to remember
In this answer, we saw that the first question is whether the two major versions share package names. If they do not, as with Jackson 2 and Jackson 3, they can coexist at the cost of two configurations and conversions at the boundary. If they do, we upgrade the older consumer whenever possible, shade and relocate inside one library when it does not expose the dependency, and use class loader or process isolation only when nothing else works. The lasting fix is libraries that keep third-party types out of their public APIs.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
It depends first on packages. If the two major versions use different package names, as Jackson 2 (com.fasterxml.jackson) and Jackson 3 (tools.jackson) do, both can sit on the classpath and each library uses its own. If they share package names, only one copy can win, so we upgrade the older consumer (the cleanest fix), shade and relocate the dependency inside one library, or, only when nothing else works, isolate it in a separate class loader or process. Longer term, we ask library owners not to expose third-party types in their public APIs, which is what makes these conflicts hard.
Why this question is asked
Diamond conflicts like this appear the moment a popular library releases a new major version. One internal library moves early, another stays on the old version, and our service needs both. Interviewers ask about it because the right answer depends on a detail many people miss, whether the packages changed, and because the options trade engineering effort against long-term risk. In this answer, we will recap why the classpath can hold only one copy of a class, look at the case where packages differ, walk through the options when they do not, and see how library design prevents the problem.
1A Quick Recap: One Class Name, One Class
On a normal classpath, a fully qualified class name such as com.fasterxml.jackson.databind.ObjectMapper can be loaded only once. If two jars both contain that class, the class loader takes the first one it finds and ignores the other. Maven and Gradle know this, so when two paths in the dependency tree ask for different versions of the same artifact, they pick one (Maven the nearest declaration, Gradle the highest version) and drop the other.
That is fine for small differences. A major version, by the rules of semantic versioning, is allowed to break compatibility: remove methods, change signatures, move classes. So if library A was compiled against version 2 and library B against version 3 with the same packages, whichever version the build picks, the other library may call a method that no longer exists and fail with NoSuchMethodError at runtime.
2When the Packages Differ, Both Can Coexist
Some projects change their package name with a new major version precisely to avoid this. Jackson 3 moved its core packages from com.fasterxml.jackson to tools.jackson and changed its Maven group id to tools.jackson.core (the annotations module keeps its old package, so check your exact modules). To the JVM, tools.jackson.databind.ObjectMapper and com.fasterxml.jackson.databind.ObjectMapper are two unrelated classes, so both jars can be on the classpath at once.
Notice what we pay for this: two copies of the library in memory, two sets of configuration to keep consistent (date formats, naming strategies, registered modules), and objects that cannot be passed between them. If library A returns a Jackson 2 JsonNode and library B expects a Jackson 3 JsonNode, we must convert, usually through a String or bytes. Spring Boot 4 uses Jackson 3 by default, so this exact situation is common during migrations; it is workable as a transition, not as a destination.
3When the Packages Are the Same: The Options
If both versions share package names, only one can be on the flat classpath, so we have to change something. The options, from the cleanest to the most drastic, are compared below.
| Option | What it costs | When to choose it |
|---|---|---|
| Upgrade the older consumer | Work in that library; a release and some testing | Almost always first; it removes the conflict |
| Shade and relocate in one library | Bigger jar, duplicated security patches | The library is internal and cannot upgrade soon |
| Separate class loader | Complex code, subtle class identity bugs | Plugin systems; rarely for ordinary services |
| Separate process | A network call and a new deployment | A legacy component that will never upgrade |
Upgrading the older consumer is usually the cleanest fix, because after it the service has one version and no special build tricks. If the library is ours, we do the upgrade; if it belongs to another team, we offer help or a pull request. It also prevents the next conflict, because a library that is kept current conflicts less often.
4Shading and Relocating
Shading means copying a dependency's classes into our own jar. Relocating means renaming their packages while doing so, so that the copy no longer clashes with anyone else's. The Maven Shade plugin and the Gradle Shadow plugin both do it, and they also rewrite our bytecode to use the new names.
But there is a catch: relocation only works if library A does not expose Jackson types in its public API. If a method of A returns a JsonNode, after relocation it returns com.acme.liba.shaded.jackson...JsonNode, which no caller can use. We also take on the job of updating the shaded copy when a security fix is released, because vulnerability scanners may not recognise relocated classes, and every library that shades its own copy grows the final artifact.
5Class Loaders and Separate Processes
A separate class loader can load one version of a library for one component, so two versions live side by side even with the same package names. Application servers and plugin systems work this way. For an ordinary Spring Boot service it is rarely worth it: objects created in one class loader are different classes from the same-named classes in the other, so passing them across fails with ClassCastException, and debugging becomes hard.
A separate process is the bluntest form of isolation: run the component that needs the old version as its own small service and call it over HTTP. It works for a legacy component that will never be upgraded, but we now pay for a network hop, its failure modes and a deployment to operate. I would choose either only when upgrading and shading are not possible.
6Preventing It: Keep Third-Party Types Out of Public APIs
The real reason this conflict is painful is that the internal libraries leak Jackson into their public API. If a library exposes JsonNode or ObjectMapper in its method signatures, its callers are tied to the same Jackson version, and the library cannot relocate or swap it. If it instead exposes its own types, such as a plain record or a Map, the Jackson version becomes a private detail that the library can shade or change at will.
So the long-term fix is a conversation with the library owners: keep third-party types out of public APIs, depend on as little as possible, and follow the company's platform BOM so that libraries move to new majors together rather than one at a time.
7Follow-up questions
How do you detect this conflict before it reaches production?
Maven Enforcer's dependencyConvergence rule fails the build when two paths request different versions of the same artifact, and Gradle's failOnVersionConflict does the same. They force someone to decide which version to use. A test suite that exercises both libraries' main paths then catches NoSuchMethodError and similar errors in CI rather than in production.
Is it safe to force the newer version on the old library without changing it?
Sometimes. If the old library only uses parts of the API that did not change, forcing the newer version may work, and good tests can show that. But a major version is allowed to break anything, so we must test the old library's real code paths with the new version, and we should treat it as a temporary decision with an owner rather than a permanent fix.
Does the Java module system solve this?
Not for this case. JPMS does not allow two modules with the same packages in one layer, and it does not support loading two versions of a module side by side without creating separate module layers, which is similar in complexity to using separate class loaders. It does make the conflict visible early, because split packages fail at startup.
8Conclusion
In this answer, we saw that the first question is whether the two major versions share package names. If they do not, as with Jackson 2 and Jackson 3, they can coexist at the cost of two configurations and conversions at the boundary. If they do, we upgrade the older consumer whenever possible, shade and relocate inside one library when it does not expose the dependency, and use class loader or process isolation only when nothing else works. The lasting fix is libraries that keep third-party types out of their public APIs.
Open with
The first thing I would check is whether the two major versions use different packages. Jackson 3 moved to tools.jackson, so Jackson 2 and 3 can both be on the classpath, each library uses its own, and I only pay for two configurations and converting objects where they meet.
Then, if they want more
If the versions share packages, only one copy can win on the classpath, and the other library will break with errors like NoSuchMethodError. Then my first choice is to upgrade the older consumer, because it leaves one version and no build tricks.
If that cannot happen soon and the library is internal, it can shade and relocate its copy with the Maven Shade or Gradle Shadow plugin, which works only if it does not expose those types in its API, and which means bigger jars and patching the shaded copy for security fixes.
Separate class loaders or a separate process are a last resort for legacy components. Long term, I would ask library owners to keep third-party types out of their public APIs and to follow the platform BOM, so versions move together.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Maven guides, Gradle user manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Two internal libraries you depend on need incompatible major versions of the same...": https://scrivio-interview-library.netlify.app/java/dependency-and-supply-chain/6e3b05cd66/