Having read this Gradle documentation I understand the difference between api
and implementation
. However I'd like to know if there's a difference between implementation
and the deprecated runtime
.
According to this table there is no difference in behavior, but using runtime
in practice seems to "leak" the compile classpath when I was trying it out and so the classes I was trying to hide was actually being exposed to the consuming module.
Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.
Runtime classpath – Those dependencies which are required to actually run the compiled Java code.
The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.
Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path. Publications means the outcomes of the project, such as test class files, build files and war files.
implementation
dependencies are added to the compilation classpath of the project they are declared in. That is not the case for runtime
dependencies.
If you're talking purely about how implementation
and runtime
dependencies affect consumers of the project, the 4.6 release notes state that runtime
dependencies have always been included on the compilation classpath, which is why you're seeing the leakage.
If you published a library with implementation
dependencies, those dependencies would be marked as runtime
scope in the POM, and I suspect that they would also be included in the compilation classpath of consuming projects. You would need to enable the IMPROVED_POM_SUPPORT
feature to change that.
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