how to tell gradle to download all the source jars

gradle download sources intellij
gradle download jar source
download jar using gradle
gradle jar task
gradle dependencies
intellij cannot download sources
how to import gradle project in eclipse
gradle source dependency

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.

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).

Download source JARs from maven and put them in a directory , Basically, I want to get all source JARs of my dependency, and all related source JARs and copy them to a directory. Here is my build.gradle: See here for an example and here for the gradle source code which does it for the Eclipse/Intellij plugins Get JavaDoc jars for dependencies in Gradle Even if I think, that I need to change the structure of my build file, I found a solution for this specific case, so I want to provide it for others who might stumble upon the same problem.

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.

Eclipse plugin not downloading source if JAR found , Doing the build in maven does not result in the source jars being downloaded (​that AFAIK if you are connected to multiple remote repos it won't download the binary if you tell Maven/M2E to automatically download the sources/javadoc. Gradle’s Java support was the first to introduce a new concept for building source-based projects: source sets.The main idea is that source files and resources are often logically grouped by type, such as application code, unit tests and integration tests.

Another catch not mentioned in other answers is when you are using mavenLocal() repository in your gradle.build file. If there are downloaded jar in that local maven repo but no downloaded sources or javadocs in that repo, then gradle will not even try to download javadocs or sources for you. Even with enabled eclipse.classpath.downloadJavadoc and eclipse.classpath.downloadSources.

The solution is to remove mavenLocal() from repositories or place it to bottom of the list. Or you can setup maven to download sources and javadocs and clean your maven local repository (~/.m2/repository).

A more detailed description of the problem is here.

Building Java Libraries, The first time you run the build, Gradle will check whether or not you already If not, the libraries will be downloaded and stored there. All of this happens without any additional configuration in the build script your project sources are arranged in a conventional project layout. In this quick article, we'll cover creating a “fat jar” in Gradle. Basically, a fat jar (also known as uber-jar) is a self-sufficient archive which contains both classes and dependencies needed to run an application.

Here is how to add the required configuration in Gradle using the IDEs' plugins:

For Eclipse:

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

eclipse {
    classpath {
        downloadJavadoc = true
        downloadSources = true
    }
}

For IntelliJ

apply plugin: 'java'
apply plugin: 'idea'

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

To run these plugins:

gradle cleanEclipse eclipse
gradle cleanIdea idea

Learning the Basics, The dependencies might need to be downloaded from a remote repository, repositories { maven { // Look for POMs and artifacts, such as JARs, here url You can specify multiple sources to tell Gradle to keep looking if a file was not found. Gradle provides different notations for module dependencies. There is a string notation and a map notation. A module dependency has an API which allows further configuration. Have a look at ExternalModuleDependency to learn all about the API. This API provides properties and configuration methods.

Piohen's comment above should be it's own answer (since it was the only solution that worked for me)

  1. Right click your project, then select "Build Path" --> "Configure Build Path";
  2. Select "Order and export"
  3. Select "Web App Libraries", and click "Bottom" button, then the "Web App Libraries" will be on the bottom;

And to get this into the Gradle Eclipse plugin (so you don't need to do it manually every time):

Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?

Building Java & JVM projects, A compileJava task that compiles all the Java source files under src/main/java A jar task that packages the main compiled classes and resources from For example, to tell Gradle that your project requires version 3.6.7 of Hibernate code, and that you want to download the library from the Maven Central repository, you  :tasks == All tasks runnable from root project == Build Setup tasks setupBuild - Initializes a new Gradle build. [incubating] == Help tasks dependencies - Displays all dependencies declared in root project 'gs-gradle'. dependencyInsight - Displays the insight into a specific dependency in root project 'gs-gradle'. help - Displays a help message projects - Displays the sub-projects of root

Managing Dependencies of JVM Projects, Final is required to compile the project's production source code. All dependencies are supposed to be looked up in the Maven Central To find out more about defining dependencies, have a look at Declaring Dependencies. For example Gradle needs to download Spring web framework JAR files from Maven Central. In this tutorial, we will show you how to use Gradle build tool to create a single Jar file with dependencies.. Tools used : Gradle 2.0; JDK 1.7; Logback 1.1.2; 1. Project Directory

EclipseClasspath - Gradle DSL Version 6.5, Keep in mind that all properties have sensible defaults; only configure them Whether to download and associate source Jars with the dependency Jars. For a complete list, see the Jar section of the Gradle Language Reference as well as the Jar and Creating Archives sections of the Gradle User Manual. Adding API documentation The java-library plugin has built-in support for Java’s API documentation tool via the javadoc task.

[PDF] Gradle User Manual: Version 6.5, common types of project — say Java libraries — by adding a layer of conventions and prebuilt functionality Complete (all) with docs and sources. Need to work with an Similarly, Gradle 5.3 will no longer try to download jars for platform. Gradle Tutorials and Guides. Here you can find project-based tutorials and topical guides to help you learn Gradle through using it. Whether you are new to Gradle or an experienced build master, the guides hosted here are designed to help you accomplish your goals.

Comments
  • :) Just wanted to draw your attention to this section of the FAQ with regards to using signatures; your questions and answers on StackOverflow are already "signed" with your user card, so in-post signatures are unnecessary.
  • well, that just sucks...a signature is something that shows up IN your post not something you have to click a link to get to...the rate at which the signature is read goes way down because of the barrier of that link(in fact, it probably drops by 90% or so :( which is very unfortunate as stackoverflow could help alot of people out with REAL signatures).
  • See this answer if you're using the Gradle wrapper: stackoverflow.com/a/46596203/924597
  • Yep, in my experience, Gradle downloads the source .jar and also links the source in the build path settings so that you can debug the source code.
  • One thing to note: after I cleaned my gradle cache I had to gradle cleanEclipse eclipse and then close and reopen the eclipse project to get eclipse to see the source again.
  • What about Android Studio? After small research, I think it can't be done…
  • Sometimes you don't see the sources in Eclipse WTP although they're downloaded by gradle. In such case you need to manually push Web App Libraries to the bottom of build path or use the solution from Andreas Kuhrwahl
  • thanks. in my case, gradle does download sources, but eclipse does not link the sources and the project... :-(
  • This is the default behavior according to gradle.org/docs/current/dsl/…
  • Maybe so, but my gradle cleanEclipse eclipse did not download source jars until I after added the indicated config to build.gradle. Thanks @skipy !
  • That was it. The solution is to remove mavenLocal() from repositories or place it to bottom of the list worked for me!
  • Wonderful, after two days searching, this worked for me.