Quick revision
The short answer
We cut the shared library's dependencies down to what it really needs, replacing trivial Commons Lang, Commons IO and Guava helpers with JDK code, and we stop exposing third-party types in its public API so the remaining ones stay implementation details. We publish a BOM that aligns versions with the platform and test the library against those versions, split it into modules so consumers take only what they use, and treat shading as a last resort because it hides vulnerable code from scanners.
What to remember
In this answer, we saw that shared library dependencies become constraints on every consumer because an application has one classpath, which leads to NoSuchMethodError at runtime. The redesign minimises dependencies by using the JDK for trivial helpers, keeps third-party types out of the public API, aligns what remains through a tested BOM, and splits the library into modules so consumers only take what they need. Shading solves conflicts but hides vulnerabilities and grows jars, so it is the last resort.
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.
We cut the shared library's dependencies down to what it really needs, replacing trivial Commons Lang, Commons IO and Guava helpers with JDK code, and we stop exposing third-party types in its public API so the remaining ones stay implementation details. We publish a BOM that aligns versions with the platform and test the library against those versions, split it into modules so consumers take only what they use, and treat shading as a last resort because it hides vulnerable code from scanners.
Why this question is asked
Version conflicts in shared libraries are one of the main reasons teams dread upgrades. A consumer adds our library, Maven or Gradle picks one Guava version for the whole application, and suddenly a NoSuchMethodError appears at runtime in code neither team wrote. Interviewers ask this design question to see whether we understand how dependency resolution works and how a library's design choices push conflicts onto its consumers. In this answer, we will see why the conflicts happen, then go through the redesign: fewer dependencies, no leaked types, a BOM with tested versions, modules, and why shading is the last resort.
1Why Consumers See Version Conflicts
A Java application has one classpath, so it can hold only one version of each library. When two dependencies want different versions of Guava, the build tool picks one. Maven chooses the version nearest to the root of the dependency tree, and Gradle chooses the highest requested version. Either way, one of the two libraries now runs against a version it was not compiled or tested with.
If the chosen version lacks a method the other library calls, the code compiles fine in each project but fails at runtime with NoSuchMethodError or NoClassDefFoundError, often only on one code path. Jackson and Guava are the usual culprits because almost everything depends on them and they occasionally remove or change APIs.
So every dependency our shared library declares becomes a constraint on every consumer. With four widely used dependencies, the chance that a consumer has a conflict with at least one of them is high. The redesign aims to reduce how many constraints we impose and how strict they are.
2Minimise What the Library Depends On
The cheapest dependency to manage is the one we do not have. In a typical shared library, Commons Lang is used for a handful of StringUtils calls, Commons IO for reading a stream into a string, and Guava for an ImmutableList and Preconditions. All of these have JDK equivalents now: String.isBlank, InputStream.readAllBytes and Files.readString, List.copyOf and Objects.requireNonNull. We replace them with a few lines of our own code and remove the three dependencies.
Jackson is different: if the library really parses JSON, it needs a JSON library. That is a legitimate dependency, and we handle it with the next steps rather than by rewriting a parser.
3Keep Third-Party Types Out of the Public API
A dependency is much worse when its types appear in our public method signatures. If a public method returns a Guava ImmutableList or takes a Jackson JsonNode, consumers compile against that type, so they are forced to have that library and a compatible version, and we can never remove it without breaking them.
Notice the Gradle java-library plugin makes the distinction explicit: implementation dependencies are needed at runtime but are not on the consumer's compile classpath, while api dependencies are. In Maven the published POM is less precise, but the design rule is the same. Once Jackson is an implementation detail, we could later replace it without a major version, and consumers cannot accidentally rely on it through us.
4Publish a BOM and Test Against Platform Versions
Conflicts are not avoidable entirely, so the goal is that everyone ends up on the same, tested versions. We publish a BOM, a bill of materials: a POM that lists versions in its dependencyManagement section without adding dependencies. Consumers import it, and every library it lists resolves to the versions in it. Ideally our library's versions are aligned with the company platform BOM or the Spring Boot BOM, so we are not fighting the framework's choice of Jackson.
A BOM is only a promise unless we test it. In the library's build, we run its test suite against the versions in the current platform BOM, and against the oldest Spring Boot line we still support. A small build matrix with two or three combinations catches most incompatibilities before a consumer does.
5Split the Library Into Modules
Often consumers complain about dependencies they never use: a service that needs our HTTP header helpers still gets the JSON rule engine and its Jackson dependency. Splitting the library into focused modules, for example shared-headers, shared-json and shared-testing, lets each consumer take only what it uses, and each module carries only its own dependencies.
- platform-bomaligns versions of all shared modules and their dependencies
- shared-headersno third-party dependencies, JDK only
- shared-jsonJackson as an implementation dependency
- shared-testingtest scope only: JUnit, AssertJ
- JDKString,
List.copyOf,Files.readStringreplace small helpers
5 layers, from the top down. Step through them one at a time.
Each module brings only its own dependencies; the BOM keeps the rest aligned.
The pieces fit together: fewer dependencies, implementation-only use, a BOM to align what remains, and modules so that the remaining dependencies reach only the consumers that need them.
6Why Shading Is the Last Resort
Shading, done with the Maven Shade plugin or Gradle Shadow, copies a dependency's classes into our jar under a renamed package, for example com.example.shaded.guava. The consumer then has no conflict, because our copy has a different name. It sounds perfect, and that is why it is overused.
The costs are real. Scanners that identify libraries by their Maven coordinates no longer see the shaded Guava, so a vulnerability in it stays hidden, and when we do find it, every consumer must wait for us to release a new version. The jar grows, sometimes by megabytes. Stack traces show renamed packages, and two shaded copies of the same library can sit in one application, wasting memory. So we shade only when a dependency is truly needed, cannot be hidden behind our API, and keeps conflicting despite a BOM. When we do, we record the shaded version in an SBOM so scanners still know it is there.
7Follow-up questions
Is using provided or optional scope a good way to avoid conflicts?
Sometimes. Marking a dependency optional means the consumer must add it themselves, which works for features only some consumers use, such as an optional Micrometer integration. But it moves the problem rather than solving it, and if the consumer forgets, they get NoClassDefFoundError at runtime. It works best combined with modules, where the optional feature lives in its own module with a normal dependency.
How do you know whether removing Guava from the library is safe for consumers?
If Guava types were never in our public API, removing it changes nothing for consumers' compilation. Some consumers may have used Guava without declaring it, relying on us to bring it in. A release note and a minor version bump give them warning, and their build fails clearly at compile time, which is the easy kind of failure.
8Conclusion
In this answer, we saw that shared library dependencies become constraints on every consumer because an application has one classpath, which leads to NoSuchMethodError at runtime. The redesign minimises dependencies by using the JDK for trivial helpers, keeps third-party types out of the public API, aligns what remains through a tested BOM, and splits the library into modules so consumers only take what they need. Shading solves conflicts but hides vulnerabilities and grows jars, so it is the last resort.
Open with
I would start by remembering why the conflicts happen: an application has one classpath, so when our library wants one Guava or Jackson version and something else wants another, the build tool picks one and somebody runs against a version they were not tested with.
Then, if they want more
So every dependency we declare is a constraint on every consumer. My first step is to remove dependencies we barely use. Commons Lang, Commons IO and Guava are often there for a few helpers the JDK has now, like isBlank, readAllBytes and List.copyOf.
Second, I make sure no third-party types appear in our public API; methods take and return JDK or our own types, and with Gradle's java-library plugin I declare Jackson as implementation rather than api, so consumers do not compile against it and we can change it later.
Third, I publish a BOM aligned with the platform or Spring Boot versions, and I test the library against those versions in a small build matrix, so the promise is real. Fourth, I split the library into modules so a service that needs our headers helper does not get the JSON engine and its dependencies.
Shading I keep as a last resort, because it hides the shaded library from vulnerability scanners, increases jar size and makes every security fix wait for our 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 official documentation for the version you use. 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 shared internal library depends on Commons Lang, Commons IO, Guava and Jackson....": https://scrivio-interview-library.netlify.app/java/utility-libraries/360400d492/