I'm developing a custom gradle plugin and the dependencies for my plugin project look like this:
dependencies {
compile gradleApi()
compile localGroovy()
compile('com.xxx.oozie:oozie-dsl-parser:1.0.127') {
exclude module: 'groovy-all'
}
testCompile('org.spockframework:spock-core:1.0-groovy-2.3') {
exclude module: 'groovy-all'
}
}
However, in the interest of reproducible builds, I'm wondering if using localGroovy()
and gradleApi()
is advisable.
After much googling, although I could replace localGroovy()
with a specific version of groovy, I can't seem to find a definitive answer on what I would replace gradleApi()
with.
Do you guys have any suggestions?
Thanks!
There are two general types of plugins in Gradle, binary plugins and script plugins.
gradleApi() Creates a dependency on the API of the current version of 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.
If the project requires a specific version of a dependency on a configuration-level then it can be achieved by calling the method ResolutionStrategy. force(java. lang. Object[]).
Looking at https://github.com/gradle/gradle/issues/1835 it seems like there is no explicit dependency you can use for that purpose.
Although not equivalent to gradleApi()
, if you are developing for Android you might be interested in the com.android.tools.build:gradle-api:3.3.2
dependency.
I suggest applying the java-gradle-plugin
. It adds the gradleApi()
dependency automatically and also includes some other boilerplate configurations: https://docs.gradle.org/current/userguide/javaGradle_plugin.html#gsc.tab=0
The version of the gradleApi()
that is added as dependency depends on the Gradle version that you are using the build the project. For example if your wrapper has Gradle 2.14.1 the used Gradle API will be of that version.
You also do not have to worry about localGroovy()
because it is already included in the gradleTestKit()
dependency which is added by the plugin: https://docs.gradle.org/current/userguide/test_kit.html#sub:test-kit-automatic-classpath-injection&gsc.tab=0
Here is an example:
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
dependencies {
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}
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