Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 966
xuanzhui Avatar asked Jul 15 '15 09:07

xuanzhui


People also ask

Where are gradle dependencies downloaded to?

The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.

Where does gradle download dependencies on Windows?

gradle folder. The compiled scripts are usually in the . gradle folder in your project folder. Now if you run gradle showMeCache it should download the dependencies into the cache and print the full path.

How do I sync gradle dependencies?

Simply open the gradle tab (can be located on the right) and right-click on the parent in the list (should be called "Android"), then select "Refresh dependencies". This should resolve your issue.


1 Answers

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.

like image 97
Thomas Avatar answered Oct 10 '22 10:10

Thomas