All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.freefair.gradle.plugins.maven.javadoc.JavadocLinksPlugin Maven / Gradle / Ivy

There is a newer version: 8.11
Show newest version
package io.freefair.gradle.plugins.maven.javadoc;

import io.freefair.gradle.plugins.okhttp.OkHttpPlugin;
import lombok.Getter;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.javadoc.Javadoc;

@Getter
public class JavadocLinksPlugin implements Plugin {

    private Project project;

    @Override
    public void apply(Project project) {
        this.project = project;

        OkHttpPlugin okHttpPlugin = project.getPlugins().apply(OkHttpPlugin.class);

        project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
            TaskProvider javadoc = project.getTasks().named(JavaPlugin.JAVADOC_TASK_NAME, Javadoc.class);

            SourceSet main = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName("main");
            Configuration compileClasspath = project.getConfigurations().getByName(main.getCompileClasspathConfigurationName());

            project.afterEvaluate(p -> {
                compileClasspath.getAllDependencies()
                        .withType(ProjectDependency.class)
                        .all(projectDependency -> p.evaluationDependsOn(projectDependency.getDependencyProject().getPath()));

                javadoc.configure(jd -> {
                    ResolveJavadocLinks rjd = new ResolveJavadocLinks(okHttpPlugin.getOkHttpClient());
                    rjd.resolveLinks(jd, compileClasspath);
                });
            });
        });
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy