Gradle:将IntelliJIdea中的source和javadoc附加到本地文件 [英] Gradle: Attach source and javadoc to local file in IntelliJIdea
问题描述
我正在使用gradle(v1.9)和IntelliJIdea(v12.1.6)。我有一个简单的java项目和一个 build.gradle
文件。一个依赖项不在maven central,所以我已经将这些jar放入 lib
文件夹中。
问题 h1>
对于位于maven central的依赖项,gradle使用javadoc和source(位于$ project / .idea / libraries)正确地生成库xml文件。对于本地依赖(JNativeHook),不附加这样的源代码或javadoc。作为比较,这两个xml文件:
使用源代码和javadoc附件
< component name =libraryTable>
< library name =jackson-core-2.2.3>
< CLASSES>
< root url =jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/1a0113da2cab5f4c216b4e5e7c1dbfaa67087e14/jackson -core-2.2.3.jar!//>
< / CLASSES>
< JAVADOC>
< root url =jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/6021971970a43ae0c22f378cfb5813af869caab/jackson -core-2.2.3-javadoc.jar!//>
< / JAVADOC>
< SOURCES>
< root url =jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/b1c4a6c3c26dfc425efd53c00217868b60d07de9/jackson -core-2.2.3-sources.jar!//>
< / SOURCES>
< / library>
< / component>
没有源代码和javadoc附件
< component name =libraryTable>
< library name =JNativeHook-1.1.4>
< CLASSES>
< root url =jar://$PROJECT_DIR$/lib/JNativeHook-1.1.4.jar!//>
< / CLASSES>
< JAVADOC />
< SOURCES />
< / library>
< / component>
其他信息
构建文件外观像这样:
apply plugin:'java'
apply plugin:'idea'
idea {
模块{
downloadJavadoc = true
downloadSources = true
}
}
存储库{
mavenCentral()
flatDir(dirs:'lib')
}
依赖关系{
//将从mavenCentral()获取
编译'com.fasterxml.jackson.core: jackson-core:2.2.3'
//将从'lib'目录中获取(参见第二个存储库)
compile'org.jnativehook:JNativeHook:1.1.4'
}
sourceCompatibility = 1.7
version ='0.1'
jar {
manifest {
attributes'Implementation-Title':'ScreenShotter',
'Implementation-Version':版本,
'Main-Class':'de.fau.screenshotter.ScreenShotter
}从{
configurations.compile.collect {it.isDirectory
()? it:zipTree(it)}
}
}
我的项目结构看起来像像这样:
问题(tldr;)
如何告诉gradle创建适当的javadoc和源项并将它们添加到IntelliJ使用的xml文件?
如果您有一个二进制存储库管理器,那么通过所有方式将模块发布到那里,即可立即解决问题。否则,您必须使用 idea.module.iml.whenMerged
来微调 idea.module
挂钩或使用 idea.module.iml.withXml
挂钩。这将需要一些编码,并且我没有准备好解决方案。有关API的详细信息,请参阅 IdeaModule 在Gradle构建语言参考中。
I am using gradle (v1.9) and IntelliJIdea (v12.1.6). I have a simple java project and a build.gradle
file. One dependency is not on maven central, so I have placed the jars in the lib
folder.
Problem
For the dependencies that are on maven central, gradle builds the library xml files correcly with javadoc and source (located in $project/.idea/libraries). For the local dependency (JNativeHook), no such source or javadoc is attached. As a comparison, the two xml files:
With source and javadoc attachment
<component name="libraryTable">
<library name="jackson-core-2.2.3">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/1a0113da2cab5f4c216b4e5e7c1dbfaa67087e14/jackson-core-2.2.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/6021971970a43ae0c22f378cfb5813af869caab/jackson-core-2.2.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.3/b1c4a6c3c26dfc425efd53c00217868b60d07de9/jackson-core-2.2.3-sources.jar!/" />
</SOURCES>
</library>
</component>
Without source and javadoc attachment
<component name="libraryTable">
<library name="JNativeHook-1.1.4">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/JNativeHook-1.1.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
Additional information
The build file looks like this:
apply plugin: 'java'
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
repositories {
mavenCentral()
flatDir(dirs: 'lib')
}
dependencies {
// Will be fetched from mavenCentral()
compile 'com.fasterxml.jackson.core:jackson-core:2.2.3'
// Will be fetched from the 'lib' directory (see second repository)
compile 'org.jnativehook:JNativeHook:1.1.4'
}
sourceCompatibility = 1.7
version = '0.1'
jar {
manifest {
attributes 'Implementation-Title': 'ScreenShotter',
'Implementation-Version': version,
'Main-Class': 'de.fau.screenshotter.ScreenShotter'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
My project structure looks like this:
Question (tldr;)
How can I tell gradle to create the appropriate javadoc and source entries and add them to the xml files that IntelliJ uses?
If you have a binary repository manager, then by all means publish the module there, which solves the problem immediately. Otherwise, you'll have to fine-tune idea.module
, either using the idea.module.iml.whenMerged
hook, or using the idea.module.iml.withXml
hook. This will require a bit of coding, and I don't have a solution ready. For API details, see IdeaModule in the Gradle build language reference.
这篇关于Gradle:将IntelliJIdea中的source和javadoc附加到本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!