Home Ask Login Register

Developers Planet

Your answer is one click away!

j2emanue February 2016

What is default dependency scope in Gradle on Android?

In Gradle in Android Studio I noticed providing a dependency scope is optional. For example:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

Notice the very last two libraries don't have a compile scope attached. I left it blank and I was still able to sync gradle. What is the default scope if nothing is specified here ?


Logain February 2016

The scope is actually a label for a given dependency configuration. It depends very much on the gradle plugins you are using (i.e.: java plugin or android plugin). If you don't add any configuration label, it will be saved as an unlabeled dependency. Most of the time if you need a compile dependency and do not add the label, your build will break. If it doesn't break it could be because:

  • You were not actually needing the dependency
  • You are using a gradle plugin that handles nicely unlabeled dependencies
  • Or (more probably), the dependency is already on your build cache or partial build and therefore the compiler is still able to find the classes, but will break if you clean the project.

Related documentation on dependency configuration for gradle

Post Status

Asked in February 2016
Viewed 1,514 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life