Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell gradle to download all the source jars

Tags:

gradle

Ideally, we would like to add a task for downloading all the source jars for the first level and transitive dependencies of our project. Is there a way to do that?

If not, is there a command line option to supply like maven has to get all the sources downloaded onto our machines?

It seems like that should just be the default these days at least for first level dependencies as it gives you the javadoc in eclipse then which is very nice when doing the code completion stuff.

like image 914
Dean Hiller Avatar asked Apr 14 '12 19:04

Dean Hiller


People also ask

Does Gradle download dependencies automatically?

Gradle automatically resolves those additional modules, so called transitive dependencies. If needed, you can customize the behavior the handling of transitive dependencies to your project's requirements.

Where does Gradle store downloaded jars?

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.


2 Answers

The eclipse task can be configured with downloadSources. Following is an example of that configuration

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
       downloadSources=true
    }
}

So run

gradle cleanEclipse eclipse

to have it download sources.

like image 80
skipy Avatar answered Oct 23 '22 15:10

skipy


If you use Eclipse and want to navigate the source code of your dependencies there, then the Eclipse plugin does this for you.

Install the eclipse plugin by adding apply plugin: "eclipse" to your build.gradle file. Then run gradle eclipse to generate the Eclipse .project, .classpath and .settings files. The plugin will download all available sources automatically and add references them in the .classpath file (see the sourcepath attribute of the classpathentry element).

To import the project into Eclipse, choose File > Import... > Existing Projects into Workspace and select your project.

(I'm not sure whether the Idea plugin does the same for Idea users, but it may do).

like image 29
Martin Dow Avatar answered Oct 23 '22 17:10

Martin Dow