DevOps / Gradle8 Interview Questions
What is the difference between the compileOnly, implementation, and api configurations?
All three affect the compile classpath, but they differ in runtime availability and visibility to downstream consumers.
| compileOnly | implementation | api |
| Compile-time only, NOT on the runtime classpath. | Compile-time AND runtime classpath, but hidden from consumers. | Compile-time AND runtime classpath, AND exposed to consumers. |
| Use for annotation processors or provided-at-runtime APIs (e.g. servlet-api). | Default choice for most internal dependencies. | Use only when the dependency's types appear in your own public API. |
| Not packaged into the final artifact. | Packaged, but not exposed transitively. | Packaged AND propagated to anyone depending on this module. |
The general rule of thumb: default to implementation unless you have a specific reason not to. Reach for api only when a type from that dependency literally appears in a method signature or field of your own public API (otherwise consumers who never see that type still get it forced onto their compile classpath); reach for compileOnly when the dependency is guaranteed to be provided by the runtime environment itself and shouldn't be bundled.
More Related questions...
