My Gradle project is pulling in some jar dependencies from file like this:
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
}
I have downloaded the Javadocs for one of the dependencies as a zip file, how do I add the Javadocs in Eclipse?
When I right click on the Gradle dependency and try to add Javadocs I see this:
The current class path entry belongs to container 'Gradle Dependencies (persisted)' which does not allow user modifications to Javadoc locations on its entries.
It may be a bit complicated for a file jar. But if you are able to get the dependency from 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
After I do gradle cleanEclipse eclipse
I get something like that 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>
You have to add the javadoc zip via eclipse
closure. It could be achieved using the following code by
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 to add the a *-sources.jar
as this also makes the javadoc hints available if it is 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
.
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