Quick revision
The short answer
I would make versions converge through a shared BOM or platform and fail builds on version conflicts with Maven Enforcer's dependency convergence or Gradle's strict conflict checks, add a duplicate-class check in CI such as the banDuplicateClasses rule, and require every shaded library to relocate its packages, because shading without relocation brings back the same class names. Shared internal libraries get owners and a policy on which transitive dependencies they may expose, and we track conflicts as a fleet metric and fix the worst first, since class path order silently decides which copy wins.
What to remember
In this answer, we saw why duplicate classes cause silent, order-dependent failures, and set standards for 300 services: a shared BOM with convergence checks, a duplicate-class check in CI, mandatory relocation for shading, owners and dependency policies for shared libraries, and a phased rollout tracked as a fleet metric that fixes the largest offenders first.
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.
I would make versions converge through a shared BOM or platform and fail builds on version conflicts with Maven Enforcer's dependency convergence or Gradle's strict conflict checks, add a duplicate-class check in CI such as the banDuplicateClasses rule, and require every shaded library to relocate its packages, because shading without relocation brings back the same class names. Shared internal libraries get owners and a policy on which transitive dependencies they may expose, and we track conflicts as a fleet metric and fix the worst first, since class path order silently decides which copy wins.
Why this question is asked
Duplicate classes are a slow-burning risk. Two copies of the same class sit on the class path, the JVM quietly picks one based on jar order, and everything works until a dependency upgrade, a new base image or a different launch order changes which copy wins. Then a service fails with NoSuchMethodError or strange behaviour, often in production only. Across 300 services, these incidents repeat unless the organisation changes how dependencies are managed. Interviewers ask this leadership question to see whether we can design standards and build checks that prevent a class of incident, and roll them out without stopping every team. In this answer, we will look at why duplicates are dangerous, then go through version convergence, duplicate-class checks, shading rules, library ownership, and fleet-level tracking and rollout.
1Why Duplicate Classes Are Dangerous
On the class path, the application class loader searches entries in order and uses the first match for each class. If jackson-core 2.12 and 2.17 are both present, or if a vendor jar bundles its own copy of Guava under com.google.common, every class name exists twice, and the copy that wins depends on the order of the jars. That order comes from the build tool, the packaging and the launcher, and can change with an unrelated edit to a dependency list.
The failures are confusing because they are partial: most of the library works, and only code paths that use a method or class missing in the losing copy fail, with NoSuchMethodError, NoClassDefFoundError or AbstractMethodError. They pass tests that do not hit those paths, and they can differ between the IDE and the packaged jar.
2Converge Versions With a Shared BOM
The first standard addresses two versions of the same artifact. We publish a company BOM, a bill of materials that pins versions for commonly used libraries, built on top of the Spring Boot dependency management that Spring services already use. Every service imports it, so a library has one version across the fleet unless a team deliberately overrides it.
Then we make conflicts fail the build. The Maven Enforcer plugin's dependencyConvergence rule fails when different paths in the dependency tree request different versions of the same artifact, and the requireUpperBoundDeps rule fails when the resolved version is lower than one some dependency asked for. In Gradle, a platform gives the same version alignment, and resolutionStrategy.failOnVersionConflict() makes conflicts an error.
3Check for Duplicate Classes, Not Just Versions
Version convergence does not catch the second kind of duplicate: the same classes inside two different artifacts. That happens with shaded jars, with libraries that changed their Maven coordinates, such as old javax artifacts next to new Jakarta ones under the same package, and with uber-jars of SDKs. The dependency tree looks clean, yet com/google/common/collect/ImmutableList.class exists twice.
So we add a duplicate-class check that opens every jar on the runtime class path and reports class files that appear in more than one. In Maven, the banDuplicateClasses rule from the extra-enforcer-rules project does this, as in the configuration above. Gradle builds can use an equivalent plugin; we pick one, test it and include it in the shared build conventions so teams do not each choose their own.
4Shading Must Relocate
Shading means copying a dependency's classes into our own jar. It is a legitimate way to avoid version conflicts, but only if the classes are relocated, which means moved to a different package name during the build, so they can no longer collide with the real library. Shading without relocation is the worst of both worlds: it puts a second copy of com.google.common on the class path, invisible to dependency management.
| Source | Example | Caught by |
|---|---|---|
| Two versions of one artifact | jackson-core 2.12 and 2.17 | BOM + dependencyConvergence |
| Shaded without relocation | vendor SDK bundles com.google.common | banDuplicateClasses |
| Renamed coordinates, same packages | old and new artifact of the same API | banDuplicateClasses |
| Stray jars at deploy time | extra jar in a lib folder | image build checks, startup class logging |
Our standard says any internal library that shades must relocate, and the duplicate-class check enforces it automatically, because an unrelocated shaded class shows up as a duplicate. For third-party jars that shade without relocating, we ask the vendor for a thin jar or a relocated build, or exclude and replace them.
5Owners for Shared Internal Libraries
Many duplicates start in internal shared libraries that pull in large transitive dependencies, such as a logging library or an HTTP client, at versions that fight with the services. Each shared library therefore gets an owning team and a short dependency policy: which dependencies it may expose to consumers, preferably few and managed by the company BOM, which it must declare as provided or optional, and how quickly it follows BOM upgrades. The owners review changes to the library's dependency list like an API change, because for consumers it is one.
6Rolling It Out and Tracking It Across the Fleet
Turning on failing checks across 300 services on one day would block many builds over problems that have existed for years. So we roll out in phases. First the rules run in warning mode, with fail set to false, and a pipeline step collects the reports from every build. That gives us a fleet metric: the number of services with version conflicts and with duplicate classes, and which libraries cause the most.
Then we fix the largest offenders first, often a handful of shared libraries or vendor jars that cause most of the duplicates, which clears many services at once. After that, we turn the rules to failing for new services and for any service already clean, so they cannot regress, and set a date for the rest, with an exceptions file for justified cases that names an owner and an expiry date. The metric stays on a dashboard, because the reason this matters is that class path order decides which copy wins, and that can change silently with any release.
- Enable rules in warning mode everywherecollect reports centrally
- Rank offendersshared libraries and vendor jars first
- Fix top offendersrelocate, exclude, align versions
- Is the service clean?YesSwitch its rules to failingNoAllow listed exceptions with an expiry
- Track the fleet metricconflicts and duplicates per service
5 steps in order. Play them, or step through them one at a time.
7Follow-up questions
How would you roll this out without blocking every team's build on day one?
Start in warning mode with central reporting, so teams see their findings and we see the fleet picture without breaking any build. Fix the shared root causes first, then make the rules fail only for clean and new services, and give the rest a deadline with a reviewed, expiring exceptions list. Communicating the reason, with an incident or two as examples, makes teams far more willing than an unexplained red build.
Is the module path a better answer than build checks?
It catches some of the same problems at startup, because the module system rejects two modules with the same package, but most Spring Boot services run on the class path, and migrating 300 services to modules for this reason alone is not worth it. Build checks give the protection without that cost.
What about duplicates that are identical copies?
banDuplicateClasses can be configured to ignore classes whose bytes are identical, which reduces noise from harmless cases. Even then, it is worth removing them, because the next upgrade may make them differ.
8Conclusion
In this answer, we saw why duplicate classes cause silent, order-dependent failures, and set standards for 300 services: a shared BOM with convergence checks, a duplicate-class check in CI, mandatory relocation for shading, owners and dependency policies for shared libraries, and a phased rollout tracked as a fleet metric that fixes the largest offenders first.
Open with
I would treat this as a standards problem with automated checks, not as individual bugs. First, version convergence: a company BOM on top of Spring Boot's dependency management that every service imports, plus Maven Enforcer's dependencyConvergence rule, or failOnVersionConflict in Gradle, so two versions of one artifact fail the build.
Then, if they want more
Second, a duplicate-class check, because convergence does not see the same classes inside different artifacts. banDuplicateClasses from extra-enforcer-rules opens every jar and fails when a class appears twice, and we would pick one equivalent plugin for Gradle and put it in the shared build conventions. Third, shading must relocate packages.
Shading without relocation just reintroduces com.google.common under the same name, invisible to dependency management, and the duplicate check enforces this automatically. Fourth, every shared internal library gets an owner and a policy on which transitive dependencies it may expose, reviewed like an API change. For rollout, I would not break 300 builds at once.
Start in warning mode, collect reports centrally as a fleet metric, fix the biggest offenders first, usually a few shared libraries or vendor jars, then switch rules to failing for clean and new services, with an expiring exceptions list for the rest.
Keeping the metric visible matters, because class path order decides which copy wins and that can change silently with any release.
About this answer
- Last updated
- 12 November 2026
- 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.
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 "Your company runs about 300 Spring Boot services. Several incidents came from duplicate...": https://scrivio-interview-library.netlify.app/java/class-loading/b4b16580ca/