43
votes

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

2

2 Answers

52
votes

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.

2
votes

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 .