Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - difference between implementation and runtime

Tags:

gradle

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.

like image 919
n00b Avatar asked Jul 01 '18 22:07

n00b


People also ask

What is the difference between implementation and compile in Gradle?

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+.

What is runtime in Gradle?

Runtime classpath – Those dependencies which are required to actually run the compiled Java code.

What is the difference between api and implementation scopes in Gradle?

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.

What is runtime dependency in Gradle?

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.


1 Answers

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.

like image 180
Peter Ledbrook Avatar answered Nov 15 '22 06:11

Peter Ledbrook