Gradle introduced compileOnly quite some time ago. One use case of using compileOnly (according to their blog) is: Dependencies whose API is required at compile time but whose implementation is to be provided by a consuming library, application or runtime environment.
compileOnly is the replacement — the equivalent configuration that is being deprecated is provided .
If you are working on an interface or module that provides support to other modules by exposing the members of the stated dependency you should be using 'api'. If you are making an application or module that is going to implement or use the stated dependency internally, use 'implementation'.
For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.
The api
configuration should be used for dependencies that are exported to external modules
(transitive dependency). Vice-Versa implementation
configuration should be used for dependencies that are internal to the component (not transitive dependency).
implementation vs compileOnly:
There is no similarity in their job, compileOnly
is
So compileOnly
doesn't replace the implementation
configuration job e.g:
implementation 'com.android.support:appcompat-v7:25.1.0' // can't use compileOnly here
testCompile 'junit:junit:4.12'
compile "com.google.dagger:dagger:2.8" // can't use here also
annotationProcessor "com.google.dagger:dagger-compiler:2.8" // can't use here also
compileOnly 'javax.annotation:jsr250-api:1.0' // we can use compileOnly here because it's required on run time only.
Since your case is a "multi-module", you have to use the api
configuration, until you reach the final module it's better to use implementation
.
Following graph describe those configurations:
Performance?
I think api
requires more memory because gradle will snapshot every class in that transitive module, vice versa implementation
is a preferred configuration because (as mentioned above) it's used for its own internal implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With