How to include Javadocs for Gradle dependencies in Eclipse?
My Gradle project is pulling in some jar dependencies from a file like this:
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
}
I downloaded the Javadocs for one of the dependencies as a zip file, how do I add the Javadocs to Eclipse?
When I right click on Gradle dependencies and try to add Javadocs, I see this:
The current classpath entry is owned by the Gradle Dependencies (persisted) 'container, which prevents custom Javadoc locations from being changed in their entries.
source to share
You have to add javadoc zip via closure eclipse
. This can be achieved with the following code
eclipse {
classpath {
file {
whenMerged { cp ->
// Add sources to a classpath entry
def fileReferenceFactory = new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory()
def entry = cp.entries.find{ entry -> entry.path.endsWith('$YOUR_JAR.jar') }
// add javadoc jar
entry.javadocPath = fileReferenceFactory.fromPath(file('$JAVADOC_FOLDER/$JAVADOC_FILE.zip'))
}
}
}
}
Btw. I would suggest adding a *-sources.jar
, as this also allows javadoc hints if possible. This can be done using the above code and
// add sources jar
entry.sourcePath = fileReferenceFactory.fromPath(file('$SOURCES_FOLDER/$SOURCE_FILE.jar')
instead of entry.javadocPath
.
source to share
This can be a little tricky for a file jar. But if you can get the dependency on the repo, then this is the way to go:
repositories {
mavenCentral()
}
dependencies {
compile 'javax.servlet:javax.servlet-api:3.1.0'
}
eclipse.classpath.downloadJavadoc = true
eclipse.classpath.downloadSources = false
Upon execution, gradle cleanEclipse eclipse
I get something like this in .classpath
:
<classpathentry kind="lib" path="C:/.../javax.servlet-api-3.1.0.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/C:/.../javax.servlet-api-3.1.0-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
source to share