kepinpin
kepinpin

Reputation: 115

How to use the "provided" keyword in gradle's build.gradle dependencies

I'm new to gradle. Please help me understand how to use the keyword "provided" that is in build.gradle dependencies block.

And what is the difference between this "provided" with "providedCompile" and "providedRuntime"?

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

...

dependencies {
  def presentationDependencies = rootProject.ext.presentationDependencies
  def presentationTestDependencies = rootProject.ext.presentationTestDependencies

  compile project(':domain')
  compile project(':data')

  apt presentationDependencies.daggerCompiler
  compile presentationDependencies.dagger
  compile presentationDependencies.butterKnife
  compile presentationDependencies.recyclerView
  compile presentationDependencies.rxJava
  compile presentationDependencies.rxAndroid
  provided presentationDependencies.javaxAnnotation //what is this???

  ...
}

EDIT

The project in question has no mention of

configuration {
    provided
}

and it still compiles!

The project is Android-cleanArchitecture

TIA

Upvotes: 1

Views: 1108

Answers (1)

Amnon Shochot
Amnon Shochot

Reputation: 9366

Gradle has no built in support for the provided dependency scope. However this blog (credit goes to Danny, the blog's writer) describes how it can be emulated. In short you need to provide a new configuration named "provided":

configurations {
    provided
}

Then add this configuration to the relevant source sets configurations:

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

And finally you're good to go:

dependencies {
    provided <your dependency>
}

Note that according to the blog post if you're using Eclipse there's a "major flaw" but the post also provides a workaround for that.

Upvotes: 1

Related Questions