Gradle下载源依赖项

Kyl*_*leM 7 java gradle

在gradle中,我有以下build.gradle,导致很多JAR被复制到'sources'文件夹,但只有jersey-media-moxy-2.22.2-sources.jar实际上包含源代码:

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.'
}
Run Code Online (Sandbox Code Playgroud)

如何修改构建以获取所有源代码(包括传递/依赖源)?我不想要非源罐子.我不明白为什么分类器没有传递,所以请澄清我的误解.

另外,我知道这不是使用gradle的最佳方式.这是(部分)临时步骤,直到我们迁移构建系统.

Sky*_*ker 6

首先我们要提醒的是

我们需要先在idea's module sectionor中添加两件事eclipse classpath section

idea {
    module {
            //if you love browsing Javadoc
            downloadJavadoc = true

            //if you love reading sources :)
            downloadSources = true
    }
}
Run Code Online (Sandbox Code Playgroud)

或者

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

eclipse {
    classpath {
       downloadSources=true
       downloadJavadoc = true
    }
}
Run Code Online (Sandbox Code Playgroud)

资源链接:

  1. https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
  2. 依赖管理

第二

我们需要mavenLocal()从存储库部分中删除部分,存储库将放置在最顶部的部分。你已经做到了。

repositories {
    mavenLocal() // remove this
    mavenCentral()
}
Run Code Online (Sandbox Code Playgroud)

第三,

有时您在 Eclipse WTP 中看不到源代码,尽管它们是通过 gradle 下载的。在这种情况下,您需要手动将 Web 应用程序库推送到构建路径的底部。要解决,您需要遵循

  1. 右键单击您的项目,然后选择“构建路径”-->“配置构建路径”;
  2. 选择“订购并导出”
  3. 选择“Web App Libraries”,然后单击“底部”按钮,则“Web App Libraries”将位于底部;

并将其放入 Gradle Eclipse 插件中(这样您就不需要每次都手动执行): 为什么 Eclipse 不将第 3 方库源文件附加到 WTP-faceted Gradle 项目?

感谢@jasop

更新:

我想向您提供更新,现在我可以下载所有 javadoc 和源 jar 文件。但我无法将它们复制到源文件夹中。我尝试下载 javadocs 和源 jar 的成功尝试如下:

build.gradle文件如下:

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.'
}
Run Code Online (Sandbox Code Playgroud)

命令提示符中的输出:下载 javadocs 和源 jar 文件

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>
Run Code Online (Sandbox Code Playgroud)


Mr0*_*son 4

Gradle 没有任何与依赖项的“源”配置相关的 API。第 7 章 依赖关系管理基础知识

答案也独立于集成开发环境。如果您尚未应用特定的 IDE 插件,则需要应用该插件。

智能

apply plugin: 'idea'
idea{
    module {
        downloadJavadoc = true // defaults to false
        downloadSources = true
    }
}
Run Code Online (Sandbox Code Playgroud)

apply plugin: 'eclipse'
eclipse {
    classpath {
        downloadJavadoc = true
        downloadSources = true
    }
}
Run Code Online (Sandbox Code Playgroud)