首先我们需要提醒一下
在IDEA的模块部分
或Eclipse的classpath部分
,我们需要先添加两个东西。
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
或者
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
downloadSources=true
downloadJavadoc = true
}
}
资源链接:
- https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
- 依赖管理
其次,
我们需要从存储库部分中移除 mavenLocal()
部分,并将存储库放置在最顶部的部分。你已经完成了这一步。
repositories {
mavenLocal()
mavenCentral()
}
第三步:
有时候,即使使用gradle已经下载了源代码,但在Eclipse WTP中仍然看不到源文件。这种情况下,您需要手动将Web应用程序库推送到构建路径的底部。
解决方法如下:
- 右键单击项目,然后选择“Build Path”-->“Configure Build Path”;
- 选择“Order and export”;
- 选择“Web App Libraries”,点击“Bottom”按钮,然后“Web App Libraries”将会处于底部位置;
为了让Gradle Eclipse插件自动执行上述操作(这样每次都不需要手动进行),请参考以下链接:Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?
感谢@jasop
更新:
我想告诉你们一个最新进展:现在我可以下载所有的javadoc和源代码jar文件了。但是我无法将它们复制到源代码文件夹中。以下是我成功尝试下载javadoc和源代码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.'
}
在命令提示符中输出:下载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>