xuanzhui
xuanzhui

Reputation: 1418

How to Make Gradle Download Dependency Libraries to Project Directory

Is there a way that makes gradle download dependency libraries to the project directory, just like maven does? I know that gradle keeps its own cache in local machine directory, but how can I know what libraries will be used for my project, especially the library I defined in the build.gradle file has its own dependency?

Upvotes: 19

Views: 20906

Answers (1)

Thomas
Thomas

Reputation: 4330

To know what libraries will be used for your project you can use dependencies task. It will help you to find out the dependencies of your module and its recursive dependencies.

If your module name is app, then you can try gradle :app:dependencies in the project directory. You'll get something like below as output.

compile - Classpath for compiling the main sources.
\--- com.android.support:appcompat-v7:22.2.0                             
     \--- com.android.support:support-v4:22.2.0
          \--- com.android.support:support-annotations:22.2.0

Here com.android.support:appcompact-v7:22.2.0 is dependency of the module and the one below is its recursive dependency.

If you really what to get the dependencies in your project directory, then you can create a task for it like this.

task copyDependencies(type: Copy) {
   from configurations.compile   
   into 'dependencies'
}

now you can run gradle :app:copyDependencies to get all the dependencies in location <projectDir>/app/dependencies. Note that this just give you the dependencies in your project directory and gradle is still resolving the dependencies from the local cache.

Upvotes: 23

Related Questions