I’m using Gradle 6.0.1 and I had Gradle generate a default Kotlin library project for me, which adds the java-library plugin. According to the documentation, this adds the implementation() and api() functions to use in the dependencies block. However, even if I remove this plugin, I am still able to call both api() and implementation() and run all tasks normally. In other words, it doesn’t actually seem the plugin is doing anything, which seems strange. Am I missing something?
The Java plugin adds the ability to declare dependencies on the implementation configuration, but not the api configuration. It does add the ability to properly consume other modules that have api dependencies though (it adds the apiElements configuration for this).
The Kotlin plugin itself is actually adding the api configuration that you can add dependencies to and it does set up a few additional items if the java-library plugin is applied. Will you notice the difference? Depending on what you are doing, maybe not.
When you use the Java Library plugin, consumers (which resolve the apiElements configuration) only have the classes directory (not the entire JAR) put on the compilation classpath. This code is registering the output directory for the compiled Kotlin classes as an additional artifact as well as that it is built by the Kotlin compilation task. This causes the Kotlin compilation to correctly occur before the other project uses the result of resolving apiElements for its own compilation.