简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM