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.
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>
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With