Gradle loading source dependencies

In gradle I have the following build.gradle, which leads to copying a large number of JAR files to the "sources" folder, but only jersey-media-moxy-2.22.2-sources.jar actually contains the source code

defaultTasks 'run' repositories { mavenCentral() } configurations { sources { description = 'sources download' transitive = true } copysource { extendsFrom sources } } dependencies { sources group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2', classifier: 'sources' } task copySources(type: Copy) { println 'Copying dependencies to sources directory' into "sources/" from configurations.copysource } task run (dependsOn: ['copySources']){ println 'Downloading JARs' } run << { println 'Downloads complete. Finished.' } 

How can I change the assembly to get the source code (including transitive / dependency sources)? I do not want to use non-original banks. I do not understand why the classifier is not applied transitively, so please clarify my misunderstanding.

Also, I understand that this is not the best way to use gradle. This is (part of) the time step until we transfer the build system.

+6
source share
2 answers

Gradle does not have an API related to the "source" configuration for dependencies. Chapter 7. Dependency Management Basics

The answer is also independent of the IDE. You need to use a special IDE plugin if you have not already done so.

IntelliJ

 apply plugin: 'idea' idea{ module { downloadJavadoc = true // defaults to false downloadSources = true } } 

Eclipse

 apply plugin: 'eclipse' eclipse { classpath { downloadJavadoc = true downloadSources = true } } 
+2
source

First of all, we must recall that

we need to add 2 things first in the idea module section or eclipse classpath section

 idea { module { //if you love browsing Javadoc downloadJavadoc = true //if you love reading sources :) downloadSources = true } } 

or

 apply plugin: 'java' apply plugin: 'eclipse' eclipse { classpath { downloadSources=true downloadJavadoc = true } } 

Resource Link:

Secondly

we need to remove the mavenLocal() from the repository section, and the repositories will be placed in the very top section. You have already done this.

 repositories { mavenLocal() // remove this mavenCentral() } 

Thirdly,

Sometimes you don’t see sources in Eclipse WTP, although they are loaded using gradle. In this case, you need to manually direct the web application libraries to the bottom of the build path. To solve, you need to follow

  • Right-click your project, then select "Build Path" β†’ "Configure Build Path";
  • Select Order and Export
  • Select "Web Application Libraries" and click the "Bottom" button, then the "Web" Application Libraries "will be at the bottom;

And to get this in the Eclipse Gradle plugin (so you don’t have to do it manually every time): Why does Eclipse not attach the source files of third-party libraries to the Gradle project with WTP support?

Credit goes to @jasop

UPDATE:

I want to inform you that now I can download all javadocs and jar files of source files. But I can not copy them to the source folder. My successful attempt to try loading javadocs and jour sources is given below:

build.gradle file is below:

 group 'com.waze' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'eclipse' sourceCompatibility = 1.8 repositories { mavenCentral() } configurations { sources { description = 'sources download' transitive = true } copysource { extendsFrom sources } } eclipse { classpath { downloadSources = true downloadJavadoc = true } } dependencies { compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2' sources group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2', classifier: 'javadoc' sources group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2', classifier: 'sources' } task copySources(type: Copy) { println 'Copying dependencies to sources directory' into "sources/" from configurations.copysource } task run (dependsOn: ['copySources']){ println 'Downloading JARs' } run << { println 'Downloads complete. Finished.' } 

Command line output: loading javadocs and jar files of source files

 Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\PCPC>F: F:\>cd F:\eclipse\workspace\log4j_sift-master F:\eclipse\workspace\log4j_sift-master>gradle cleanEclipse eclipse Copying dependencies to sources directory Downloading JARs :cleanEclipseClasspath :cleanEclipseJdt :cleanEclipseProject :cleanEclipse :eclipseClasspath Download https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-common/ 2.22.2/jersey-common-2.22.2-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-common/ 2.22.2/jersey-common-2.22.2-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/jersey/ext/jersey-entity-f iltering/2.22.2/jersey-entity-filtering-2.22.2-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/jersey/ext/jersey-entity-f iltering/2.22.2/jersey-entity-filtering-2.22.2-javadoc.jar Download https://repo1.maven.org/maven2/org/eclipse/persistence/org.eclipse.pers istence.moxy/2.6.0/org.eclipse.persistence.moxy-2.6.0-sources.jar Download https://repo1.maven.org/maven2/javax/ws/rs/javax.ws.rs-api/2.0.1/javax. ws.rs-api-2.0.1-sources.jar Download https://repo1.maven.org/maven2/javax/ws/rs/javax.ws.rs-api/2.0.1/javax. ws.rs-api-2.0.1-javadoc.jar Download https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1. 2/javax.annotation-api-1.2-sources.jar Download https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1. 2/javax.annotation-api-1.2-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/jersey/bundles/repackaged/ jersey-guava/2.22.2/jersey-guava-2.22.2-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-api/2.4.0-b34/hk2- api-2.4.0-b34-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-api/2.4.0-b34/hk2- api-2.4.0-b34-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/external/javax.inject/ 2.4.0-b34/javax.inject-2.4.0-b34-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/external/javax.inject/ 2.4.0-b34/javax.inject-2.4.0-b34-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-locator/2.4.0-b34/ hk2-locator-2.4.0-b34-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-locator/2.4.0-b34/ hk2-locator-2.4.0-b34-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/osgi-resource-locator/ 1.0.1/osgi-resource-locator-1.0.1-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/osgi-resource-locator/ 1.0.1/osgi-resource-locator-1.0.1-javadoc.jar Download https://repo1.maven.org/maven2/org/eclipse/persistence/org.eclipse.pers istence.core/2.6.0/org.eclipse.persistence.core-2.6.0-sources.jar Download https://repo1.maven.org/maven2/javax/validation/validation-api/1.1.0.Fi nal/validation-api-1.1.0.Final-sources.jar Download https://repo1.maven.org/maven2/javax/validation/validation-api/1.1.0.Fi nal/validation-api-1.1.0.Final-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/javax.json/1.0.4/javax.jso n-1.0.4-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/javax.json/1.0.4/javax.jso n-1.0.4-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-utils/2.4.0-b34/hk 2-utils-2.4.0-b34-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-utils/2.4.0-b34/hk 2-utils-2.4.0-b34-javadoc.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/external/aopalliance-r epackaged/2.4.0-b34/aopalliance-repackaged-2.4.0-b34-sources.jar Download https://repo1.maven.org/maven2/org/glassfish/hk2/external/aopalliance-r epackaged/2.4.0-b34/aopalliance-repackaged-2.4.0-b34-javadoc.jar Download https://repo1.maven.org/maven2/org/javassist/javassist/3.18.1-GA/javass ist-3.18.1-GA-sources.jar Download https://repo1.maven.org/maven2/org/javassist/javassist/3.18.1-GA/javass ist-3.18.1-GA-javadoc.jar Download https://repo1.maven.org/maven2/org/eclipse/persistence/org.eclipse.pers istence.asm/2.6.0/org.eclipse.persistence.asm-2.6.0-sources.jar Download https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject -1-sources.jar Download https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject -1-javadoc.jar :eclipseJdt :eclipseProject :eclipse BUILD SUCCESSFUL Total time: 7 mins 5.896 secs F:\eclipse\workspace\log4j_sift-master> 
+2
source

All Articles