Gradle Custom Plugin: gradleApi() vs Explicit Dependency
Asked Answered
C

2

12

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!

Croce answered 24/11, 2015 at 23:50 Comment(2)
Thanks for the edit @Opal.Croce
And now it's me too. I need to build a Gradle plugin from Maven/Java, but I can't find the notorious gradleApi() dependency anywhere. Suffice to say that the decade is actually ending these days with no answer in sight. Gradle seems quite obscure in some respects.Obelize
E
3

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'
    }
}
Educt answered 10/3, 2017 at 13:12 Comment(1)
But still... where's that gradleApi() dependency? And how to I specify the specific version I want?Obelize
B
3

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.

Bookstore answered 25/3, 2019 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.