Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Custom Plugin: gradleApi() vs Explicit Dependency

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!

like image 487
nemo Avatar asked Nov 24 '15 23:11

nemo


People also ask

Which are the two types of plugins in Gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.

What is gradleApi?

gradleApi() Creates a dependency on the API of the current version of Gradle.

What is the difference between API and implementation scopes?

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.

How do I force Gradle to use specific dependency?

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[]).


2 Answers

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.

like image 150
Antimonit Avatar answered Sep 19 '22 21:09

Antimonit


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'
    }
}
like image 26
tomasulo Avatar answered Sep 20 '22 21:09

tomasulo