Quick revision
The short answer
Before adding a library, I check five things. Need: whether the JDK or an existing dependency already covers it. Health: maintenance activity, release frequency, number of maintainers, how quickly issues and security reports are answered, and its security history. Licence: whether it is compatible with how we distribute the software. Transitive dependencies: what it pulls in and whether that conflicts with what we have. And removal: how easily we can test it and replace it, which is why we keep its use behind a small interface of our own.
What to remember
In this answer, we went through five criteria for adding a library: whether it is needed at all given the JDK and existing dependencies; its health, from maintainers and releases to security history; its licence compared with how we distribute; the transitive dependencies it brings and their conflicts; and how easily we can test and remove it, which is why business-specific libraries go behind our own small interface. Recording the decision helps the next person understand why the library is there.
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.
Before adding a library, I check five things. Need: whether the JDK or an existing dependency already covers it. Health: maintenance activity, release frequency, number of maintainers, how quickly issues and security reports are answered, and its security history. Licence: whether it is compatible with how we distribute the software. Transitive dependencies: what it pulls in and whether that conflicts with what we have. And removal: how easily we can test it and replace it, which is why we keep its use behind a small interface of our own.
Why this question is asked
Adding a dependency takes one line in a build file, but it is a long-term commitment. Every library becomes code we ship, patch, upgrade and answer for in a security audit, along with everything it depends on. Interviewers ask this to see whether we have a disciplined way of deciding, rather than adding whatever solves today's problem fastest. In this answer, we will go through each criterion with what to look at and why, and finish with a short worked example.
1Need: Is It Already Covered?
The cheapest dependency is the one we do not add. Before anything else, we check whether the JDK already offers what we need. Modern Java covers a lot: HTTP calls with java.net.http.HttpClient, text helpers such as String.isBlank and strip, immutable collections with List.of, dates with java.time, concurrency with virtual threads. Then we check what the project already depends on. In a Spring Boot service, Spring itself offers retry support, caching abstractions, a RestClient, validation through Hibernate Validator and much more.
If the need is real but small, such as one helper method, writing ten lines of our own is often better than adding a library of a hundred classes for it. The question is not whether the library is good, but whether it is the smallest reasonable way to meet the need.
2Health: Will It Still Be Maintained?
A library is only as good as the people maintaining it. We look at recent commits and releases: a release in the last year is a good sign, although a small, finished library may legitimately be quiet. We look at the number of active maintainers, because a project with one person is fragile. We look at the issue tracker: are bugs answered, and how long do security reports take to be fixed? And we look at the security history in vulnerability databases, not to reject any library that has had a vulnerability, since popular ones always have, but to see how quickly and openly they were handled.
Automated signals help here. The OpenSSF Scorecard rates projects on practices such as code review, branch protection and signed releases, and sites such as deps.dev show dependency graphs and known advisories. These are a first filter; for an important dependency, a human still reads the issue tracker for ten minutes.
3Licence: Can We Use It the Way We Ship?
Open source licences differ in what they require. Permissive licences such as Apache 2.0 and MIT allow use in almost any product, as long as we keep the copyright and licence notices. Weak copyleft licences such as LGPL or MPL allow use in proprietary software, but changes to the library itself must be shared, and LGPL has conditions about how the library is linked. Strong copyleft licences such as GPL require the whole combined work to be released under the GPL when it is distributed, which is usually unacceptable for proprietary software that is shipped to customers. The AGPL extends that obligation to software offered over a network, which matters for SaaS.
So the answer depends on how we distribute. A service that only runs on our servers has fewer obligations under GPL than a product installed by customers, but AGPL changes that. Most companies keep an allow list, often Apache 2.0, MIT, BSD and similar, with legal review for everything else, and a licence scanner in the build to catch transitive surprises.
| Licence | Main obligation | Typical policy |
|---|---|---|
| Apache 2.0, MIT, BSD | keep notices; Apache adds a patent grant | allowed |
| LGPL, MPL, EPL | share changes to the library itself | allowed with review |
| GPL | combined work under GPL when distributed | legal review, usually avoided |
| AGPL | applies to network use too | usually not allowed |
| No licence stated | no permission to use at all | not allowed |
4Transitive Dependencies: What Else Comes With It?
A library brings its own dependencies, and they come with all the same questions. A small client library might pull in an old Guava, a second JSON library and a logging implementation that fights with Logback. We check before adding, not after.
Notice that each line is a problem of its own: a version conflict that may cause NoSuchMethodError, a redundant JSON library, and an unmaintained logging library with known vulnerabilities. Sometimes we can exclude transitive dependencies safely; sometimes the library really needs them, and that is a strong reason to look for an alternative. The total size and number of new jars is also worth noting, since each one adds to the attack surface.
5Removal and Testing: Can We Get Out Again?
Finally, we ask how hard it would be to remove the library if it stops being maintained, has a serious vulnerability or is replaced by a JDK feature. A library used directly in a hundred classes is expensive to leave. A library used behind one small interface of our own is cheap to leave, and also easy to replace with a fake in tests.
So a sensible rule is that libraries which fill a specific business need, such as vendor SDKs, PDF generation or a rules engine, sit behind our own interface, while foundational libraries such as Jackson or Spring are used directly because wrapping them would cost more than it saves. The decision, including the answers to all five questions, goes into a short record in the repository, so the next person knows why the library is there.
6Follow-up questions
Who should approve a new library?
For common, permissive, healthy libraries, the team itself, following the checklist. For licences outside the allow list, libraries in security-sensitive areas such as cryptography or parsing untrusted input, or anything with heavy transitive dependencies, a platform or security review. The goal is that most decisions are fast and only risky ones wait.
Is a library with no release for two years automatically unhealthy?
No. Some small libraries are simply finished and correct. What matters is whether issues and security reports still get answered and whether it works on current Java versions. A quiet but responsive project is fine; a quiet project with unanswered security issues is not.
How do you handle a library that is perfect but has a GPL licence?
Ask legal how it applies to our distribution model. For an internal service never shipped to customers, the obligations may be acceptable; for a product we distribute, usually not. Alternatives include a commercially licensed edition if the project offers dual licensing, or a different library.
7Conclusion
In this answer, we went through five criteria for adding a library: whether it is needed at all given the JDK and existing dependencies; its health, from maintainers and releases to security history; its licence compared with how we distribute; the transitive dependencies it brings and their conflicts; and how easily we can test and remove it, which is why business-specific libraries go behind our own small interface. Recording the decision helps the next person understand why the library is there.
Open with
I use five criteria. First, need: is it already covered by the JDK or by something we already depend on, like Spring? Modern Java covers HTTP clients, immutable collections, dates and much more, and for one small helper I would rather write ten lines.
Then, if they want more
Second, health: recent releases, how many active maintainers, how issues and security reports are handled, and its vulnerability history. I use OpenSSF Scorecard and deps.dev as a first filter and then read the issue tracker myself for anything important.
Third, licence: Apache 2.0, MIT and BSD are generally fine; LGPL and similar need review; GPL and especially AGPL need legal review and depend on how we distribute, since AGPL also covers network use. A licence scanner in the build catches transitive surprises.
Fourth, transitive dependencies: I run dependency:tree before adding it to see whether it brings an old Guava, a second JSON library or something unmaintained like log4j 1.x.
Fifth, removal and testing: if it serves a specific business need, like a vendor SDK, I keep it behind a small interface of our own, which makes it easy to fake in tests and to replace later. Foundational libraries like Jackson I use directly.
And I write the decision down in a short record so the next person knows why it is there.
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 "What criteria do you apply before adding a new third-party library to a production...": https://scrivio-interview-library.netlify.app/java/utility-libraries/20fc3eaa79/