Gradle Api Sources and Doc when writing Gradle Plugins
eclipse, gradle
Solution
This works for me in Eclipse:
plugins.withType(EclipsePlugin) {
plugins.withType(JavaBasePlugin) {
eclipse {
classpath {
file {
whenMerged { classpath ->
String gradleHome = gradle.getGradleHomeDir()
.absolutePath
.replace(File.separator, '/')
String gradleSourceDirectory = "${gradleHome}/src"
classpath.entries.each { entry ->
if (entry in org.gradle.plugins.ide.eclipse.model.AbstractLibrary
&& entry.library.path.contains('generated-gradle-jars')) {
entry.sourcePath =
new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory()
.fromPath(gradleSourceDirectory)
}
}
}
}
}
}
}
}
Make sure that your Gradle Home contains the source directory. If you use the wrapper this can be done by updating the `distributionUrl` to an `-all` version in the wrapper task.
You will also need to stop the Gradle daemons that are running otherwise they will keep their own "home": `./gradlew --stop`, then you can go ahead and run the task: `./gradlew eclipse`
See GRADLE-2133 (which this answer was adapted from)
Problem
The question: How do I get the sources and javadoc/groovydoc for the gradle-api code integrated into an Eclipse project? Background: I'm using Gradle to build a Gradle-plugin that I'm writing. I'm using Eclipse as an IDE for this project and my Gradle script for building this plugin is using the 'Eclipse' plugin to generate my Eclipse project. Also, I'm using Spring's Gradle plugin for Eclipse which grabs all my dependencies from my build.gradle file. The dependencies block for this Gradle script has ``` dependencies { compile localGroovy() compile gradleApi() // I want something like: 'compile gradleApiSources()' here // I want something like: 'compile gradleApiDoc()' here as well } ``` Justification: As I'm learning to write Gradle plugins, it would be helpful to be able to see the documentation and even implementation for Gradle to help me learn what I'm doing.