如何使用IntelliJ将外部库的源和javadoc添加到gradle中?
我已经使用IntelliJ和Gradle建立了一个Java项目。我的根项目中有一个build.gradle文件,我可以编译并运行我的应用程序。
I've set up a Java project with IntelliJ and Gradle. I have a build.gradle file in my root project and I can compile and run my app.
但是......我正在使用一个附带的Java库来源和javadoc zip文件。如果我在我的源代码中并想要从这个库中获取类或方法的声明,IntelliJ会调出 .class
文件而不是源 .java 文件。
However... I'm using a Java library which comes with a sources and javadoc zip file. If I'm in my source code and want to go to the declaration of a class or method from this library, IntelliJ brings up the .class
file instead of the source .java
file provided in the zip.
如何告诉gradle使用外部提供的源和javadoc拉链库?
How can I tell gradle to use the sources and javadoc zips provided with the external library?
我不确定你的库是否存储在maven存储库中。我认为是。
I'm not sure if your library is stored in a maven repository or not. I assume it is.
我知道将gradle项目导入IntelliJ的两种方法。第一个是IntelliJ的导入项目......向导,效果很好。但如果它们存在,它不会导入javadoc jar。至少我从未管理过它。
I know of two ways of importing a gradle project into IntelliJ. The first being the "Import Project..." wizard from IntelliJ which works nicely. But it does not import the javadoc jars if they exist. At least I never managed it.
第二种方法使用gradle 2.1中的idea插件。该插件为您生成项目。这样我就得到了javadoc。 build.gradle的完整工作示例:
The second method uses the idea plugin in gradle 2.1. The plugin generates the project for you. This way I got the javadoc inside. A fully working example for a build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.8.1'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.5'
}
idea{
project {
languageLevel = '1.7'
}
module {
downloadJavadoc = true // defaults to false
downloadSources = true
}
}
您可以调用 gradle cleanIdea idea
为英特尔创建项目liJ。
The you can call gradle cleanIdea idea
which creates your project for IntelliJ.
如果你的图书馆没有存储在maven资料库中,你可以简单地在你上传它的地方建立一个连接点。这将允许您使用上述方法。
If your library is not stored in a maven repository you can simply put up a nexus where you upload it. This would allow you to use the method described above.