51

I am using android studio and in project structure -> dependencies tab following options i can see:

  1. Compile
  2. Provided
  3. APK
  4. Test Compile
  5. Debug Compile
  6. Release Compile

my question: what is the difference between compile, testCompile and provided in gradle dependency

1

2 Answers 2

59

compile is the group of dependencies you need to build your application while testCompile is a group of dependencies that you need only for testing.

Look for instance at this build.gradle (taken from here)

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

This specifies that hibernate-core is needed to build your code but junit (a testing framework) is needed just for testing. Since it's not needed at runtime, it's not going to be included in the released package.

1
  • 1
    Sorry for nitpicking, but shouldn't the last line read: Since it's NOT needed at runtime, it's not going to be included in the released package. Sep 28, 2016 at 15:32
2

You should read the User Guide that comes with the distribution, or read it online at http://gradle.org/documentation/ .

In short, "compile" is for dependencies for your "main" code, "testCompile" for your test classes, and "provided" is used for dependencies that are used at compile time, but not stored in your WAR file (because they're expected to be available in your web container).

The following posting might have relevant information: Compile, Provided, APK - Android dependency scope .

1
  • 5
    The question was tagged with Android. WAR files to not apply Jun 14, 2016 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.