how to tell gradle to download all the source jars

后端 未结 6 2044
暖寄归人
暖寄归人 2020-12-04 23:53

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?

<
相关标签:
6条回答
  • 2020-12-04 23:59

    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
    
    0 讨论(0)
  • 2020-12-05 00:01

    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.

    0 讨论(0)
  • 2020-12-05 00:03

    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.

    0 讨论(0)
  • 2020-12-05 00:11

    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?

    0 讨论(0)
  • 2020-12-05 00:14

    There is only one problem here. This only works if you are generating NEW projects. If you are working on mature projects that can't be re-generated using Gradle, the above suggestions will not work.

    One thing I should add is that the version of Gradle/Builsdhip plugin strongly depends on the version of Java you use to start Eclipse. They must all be compatible. I had to switch my Eclipse (current version) from Java 11 back to Java 8 to fix Buildship (3.0.1) errors. We are, and have been, stuck on Gradle 4.2.1 for some time due to API changes in Gradle breaking our build. So to move to Java 11 we have to move to a new version of Gradle, Buildship, and Eclipse. Ugh! Oh yeah, this also fixed the issue mentioned in this thread. Source is now avalable again.

    0 讨论(0)
  • 2020-12-05 00:19

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

    0 讨论(0)
提交回复
热议问题