Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Your internal library is consumed by 80 Gradle services. Explain how you decide what goes into api versus implementation, and how you prevent the library from forcing versions onto consumers.

Only dependencies whose types appear in the library's public API, such as method signatures, public superclasses or annotations consumers must read, go into api; everything else is implementation. To avoid forcing versions on 80 consumers, the library declares plain require-style versions instead of strict pins or enforced platforms, publishes Gradle module metadata so constraints travel correctly, and leaves the final versions to each application or its platform BOM. Before each release, we build a sample of real consumers against the new version.

Why this question is asked

A library used by 80 services is part of 80 dependency graphs. Every dependency it exposes, and every version it insists on, becomes a constraint that 80 teams have to live with. A careless api declaration can make a whole fleet recompile on every release, and a single strict pin can block every service from taking a security fix. Interviewers ask this design question to see whether we think about a library from the consumer's side. In this answer, we will look at how to draw the line between api and implementation, why fewer exposed dependencies help everyone, how versions should be declared in a library, what Gradle module metadata adds, and how to test against consumers before a release.

1Drawing the Line Between api and implementation

The rule is about what consumers must see to compile against us. If a type from a dependency appears in a public or protected method signature, as a public superclass or interface, in a public field, or in an annotation consumers must process, the consumer's compiler needs that class, so the dependency is api. If the dependency is used only inside method bodies or in private fields, the consumer never names its types, so it is implementation.

Here is how that looks for an internal client library that calls a payments service.

Java
// payments-client/build.gradle.kts
plugins { `java-library`; `maven-publish` }
dependencies {
api("org.springframework:spring-web") // public method takes a RestClient.Builder
api("jakarta.validation:jakarta.validation-api") // our request types carry @NotNull
implementation("com.fasterxml.jackson.core:jackson-databind") // only used inside our mapper
implementation("io.github.resilience4j:resilience4j-retry") // retries are an internal detail
}
// public PaymentsClient(RestClient.Builder builder) -> spring-web must be api
// private final ObjectMapper mapper; -> jackson stays implementation

Notice that we look at the public surface, not at how important a library feels. Jackson is central to how the client works, but no consumer ever sees an ObjectMapper from it, so it stays hidden. A good habit is to keep public types in a small package and review its imports: every third-party import there is an api dependency, and each one should be a deliberate choice.

2Why Exposing Less Helps 80 Consumers

Every api dependency lands on 80 compile classpaths. If we upgrade it, 80 services recompile against new classes, and if we ever want to replace it, that is a breaking change for all of them. An implementation dependency still reaches their runtime classpath, but they cannot compile against it, so we are free to change or remove it in a minor release.

Exposing less also reduces conflicts. A consumer that uses Guava 33 cannot have its code accidentally compiled against our Guava, because our Guava is not on its compile classpath. Conflicts still happen at runtime, where only one version can win, but there are fewer of them to reason about, and consumers do not start depending on our internals by accident.

3Declaring Versions Without Forcing Them

A library does not know the final classpath; the application does. So a library should declare the minimum version it needs, which in Gradle is the normal require meaning of a version string, and let resolution pick a higher one if the application or another library needs it. The application, or the platform BOM it imports, decides the final versions.

Java
dependencies {
// Good for a library: a minimum, upgrades allowed
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.0")
// Harmful in a library:
// implementation("com.fasterxml.jackson.core:jackson-databind:2.17.0!!") // strictly: blocks consumers' upgrades
// implementation(enforcedPlatform("org.springframework.boot:spring-boot-dependencies:3.5.0")) // forces Boot's versions on 80 apps
// Fine: compile against the BOM without imposing it
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.5.0"))
}
Version styles in a library
DeclarationEffect on consumersUse in a library?
"g:a:2.17.0" (require)Minimum; higher versions allowedYes, the default
platform(bom)Recommendations that join resolutionYes
"g:a:2.17.0!!" (strictly)Blocks other versions; may fail resolutionNo
enforcedPlatform(bom)Overrides consumers' versionsNo
reject("2.16.0")Avoids a known broken releaseYes, sparingly

Notice the difference between platform and enforcedPlatform. A normal platform adds recommendations that take part in highest-wins resolution, so a consumer on a newer Spring Boot still gets its newer versions. An enforcedPlatform overrides everything, including the consumer's own choices, and when published it travels to every consumer. A strict version does the same for one module and can make resolution fail when a consumer needs something else. In a library, these force versions onto people who did not choose them.

Many organisations go one step further: the library depends on versions without numbers and relies on a shared platform, so the library is always built and tested against the same set that applications use. Either way, the final decision stays with the application.

4Publishing Gradle Module Metadata

When maven-publish publishes a Gradle library, it writes two descriptions: the usual pom.xml and a .module file, Gradle module metadata, in JSON. The module file carries what a pom cannot express well: separate dependencies for the API and the runtime variants, rich versions, dependency constraints, and capabilities that tell Gradle two modules provide the same thing.

Gradle consumers read the module file, so they see exactly that jackson-databind is a runtime dependency and spring-web an API dependency. Maven consumers read the pom, where Gradle maps api to compile scope and implementation to runtime scope. That mapping is close enough for most cases, but it is worth checking the generated pom once, especially if the library uses constraints or rich versions, since some of them have no exact Maven equivalent.

Step throughWhat one publication contains
  1. payments-client-2.4.0.jarthe classes
  2. payments-client-2.4.0.moduleGradle metadata: variants, constraints, rich versions
  3. payments-client-2.4.0.pomMaven view: api -> compile, implementation -> runtime

3 layers, from the top down. Step through them one at a time.

Gradle consumers use the .module file; Maven consumers use the pom.

5Testing Against Real Consumers Before Releasing

Unit tests prove the library works on its own. They do not prove it still works inside 80 different graphs. So before a release, CI builds a representative set of consumers, perhaps eight services chosen to cover old and new Spring Boot versions, against the release candidate. With a composite build this is cheap: each consumer is checked out and built with includeBuild pointing at the library, so Gradle substitutes the local library for the published one.

If a consumer fails to compile, we learn that a change was breaking for its API usage; if it fails at runtime, we usually learn about a version conflict. Either way, we find out before 80 teams do, and we can fix it or note it in the release notes.

6Follow-up questions

How do you catch an api dependency that should have been implementation?

Review the public packages' imports, and use a dependency analysis plugin, such as the community Dependency Analysis Gradle Plugin, which reports dependencies declared as api but only used internally, and the reverse. Running it in CI on the library keeps the list honest as code changes.

A consumer complains our library pulled in an old version of a dependency. What do you check?

First, whether we declared it as a minimum or pinned it. A plain version cannot downgrade the consumer's newer request under highest-wins, so the old version is probably winning because nothing else asks for a higher one, or because the consumer's own BOM manages it. dependencyInsight on their runtimeClasspath shows which. If we pinned it strictly, we remove the pin and release.

Should the library publish a BOM of its own?

If it is a family of modules that must be used at matching versions, yes: a java-platform project that lists them lets consumers align all of them with one platform() line. For a single library it adds little.

7Conclusion

In this answer, we saw that only dependencies whose types appear in the public surface belong in api, and that hiding the rest lets the library change its internals and spares 80 consumers recompilation and conflicts. A library declares minimum versions and normal platforms, never strict pins or enforced platforms, and leaves final versions to the application or its BOM. Publishing Gradle module metadata keeps variants and constraints accurate for Gradle consumers while the pom serves Maven ones, and consumer compatibility builds before each release catch breaks early.

What to say in the interviewAbout 90 seconds aloud

Open with

I decide api versus implementation by looking at the library's public surface. If a type from a dependency appears in a public method signature, a public superclass or interface, or an annotation consumers must see, it is api, because their compiler needs it.

Then, if they want more

Everything else, even something central like Jackson used inside our mapper, is implementation. With 80 consumers that matters a lot: each api dependency is on 80 compile classpaths, so upgrading it recompiles 80 services and removing it is a breaking change, while implementation dependencies can change freely. On versions, the library should state what it needs, not decide for everyone.

So we declare plain versions, which Gradle treats as a minimum, or use a normal platform to compile against the Spring Boot BOM. We never publish strictly pins or an enforcedPlatform, because those override the consumers' choices and can block security upgrades. The application or the company platform decides the final versions.

We publish with maven-publish so Gradle module metadata goes out with the pom; Gradle consumers then get the exact API and runtime variants and constraints, and Maven consumers get api as compile scope and implementation as runtime scope.

Finally, before each release CI builds a handful of representative consumers against the release candidate, using a composite build, so we find breaks before 80 teams do.

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.
Official documentation
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 "Your internal library is consumed by 80 Gradle services. Explain how you decide what...": https://scrivio-interview-library.netlify.app/java/gradle/77eb984c9b/