Gradle Api Sources and Doc when writing Gradle plugins

Question:

How to get sources and javadoc / groovydoc for gradle-api code integrated into an Eclipse project?

Reference Information:

I am using Gradle to build the gradle-plugin that I am writing. I use Eclipse as the IDE for this project, and my Gradle script to create this plugin uses the "Eclipse" plugin to create my Eclipse project. In addition, I use the Spring Gradle plugin for Eclipse, which captures all my dependencies from my build.gradle file.

The dependency 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:

Since I am learning to write Gradle plugins, it would be helpful to see the documentation and even the implementation for Gradle to help me find out what I'm doing.

+7
2

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)
                            }
                        }
                    }
                }
            }
        }
    }
}

, Gradle Home . , , distributionUrl -all .

. GRADLE-2133 ( )

+3

eclipse, , intellij, . , .

private void addGradleSourceDeps() {
    PathFactory pf = new PathFactory()
    pf.addPathVariable('GRADLE_HOME', project.gradle.gradleHomeDir)
    project.extensions.idea.module.iml.whenMerged { Module module ->
        module.dependencies.grep {
            it instanceof ModuleLibrary && ((ModuleLibrary) it).classes.grep { Path path ->
                path.relPath.substring(path.relPath.lastIndexOf('/') + 1).startsWith('gradle-')
            }
        }.each { ModuleLibrary lib ->
            // TODO this needs to be fixed for gradle 1.9 which now includes separate sub directory for each jar
            // for now a workaround is to execute the following
            // cd $GRADLE_HOME
            // for each in $(find . -mindepth 2 -maxdepth 2 -type d ! -name META\-INF); do cp -a ${each} .;done
            lib.sources.add(pf.path('file://$GRADLE_HOME$/src'))
        }
        module.dependencies.grep {
            it instanceof ModuleLibrary && ((ModuleLibrary) it).classes.grep { Path path ->
                path.relPath.substring(path.relPath.lastIndexOf('/') + 1).startsWith('groovy-all')
            }
        }.each { ModuleLibrary lib -> lib.sources.add(pf.path('file://$GROOVY_SRC_HOME$')) }
    }
}

, gradle src , GRADLE_HOME intellij ( GROOVY_SRC_HOME). , gradle 1.8, src 1.9, .

+1

Source: https://habr.com/ru/post/1533777/


All Articles