Junior — Middle
What distinguishes connecting a Gradle module using the API from the implementation method?
sobes.tech AI
Answer from AI
In Gradle, the difference between api and implementation lies in the scope of dependencies:
-
api— dependencies declared with this modifier become part of the module's API and are visible to modules that depend on it. That is, if module A depends on module B viaapi, then the dependencies of module B declared withapiwill also be accessible to module A. -
implementation— dependencies declared with this modifier are used only within the module itself and are not visible to external modules. This improves build times because changes in such dependencies do not require recompiling modules that depend on them.
Example:
dependencies {
api 'com.example:library-api:1.0'
implementation 'com.example:library-impl:1.0'
}
Here, library-api will be visible to external modules, but library-impl will not.