Skip to content

Commit

Permalink
Collect javadocClasspaths in their respective projects
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgrefer committed Jul 25, 2021
1 parent a16caae commit f0dd63f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
5 changes: 3 additions & 2 deletions examples/javadoc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: "java"
apply plugin: "io.freefair.javadocs"

dependencies {
implementation "org.springframework.boot:spring-boot-starter-data-jpa:2.1.3.RELEASE"
implementation "org.springframework.boot:spring-boot-starter-web:2.1.3.RELEASE"
implementation platform("org.springframework.boot:spring-boot-dependencies:2.1.3.RELEASE")
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-web"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.freefair.gradle.plugins.maven.javadoc;

import lombok.Getter;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.javadoc.Javadoc;

class AggregateJavadocClientPlugin implements Plugin<Project> {

@Getter
private ConfigurableFileCollection javadocClasspath;

@Getter
private TaskProvider<Task> collectJavadocClasspath;

@Override
public void apply(Project project) {
collectJavadocClasspath = project.getTasks().register("collectJavadocClasspath");
javadocClasspath = project.files().builtBy(collectJavadocClasspath);

project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
collectJavadocClasspath.configure(c -> {
c.doFirst(t -> {
Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
javadocClasspath.from(javadoc.getClasspath().getFiles());
});
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
Expand All @@ -13,8 +13,6 @@
import org.gradle.external.javadoc.StandardJavadocDocletOptions;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;

Expand All @@ -26,7 +24,7 @@ public class AggregateJavadocPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {

Configuration classpathConfiguration = project.getConfigurations().create("aggregateJavadocClasspath");
ConfigurableFileCollection aggregateClasspath = project.files();

aggregateJavadoc = project.getTasks().register("aggregateJavadoc", Javadoc.class, aggregateJavadoc -> {
aggregateJavadoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
Expand All @@ -40,23 +38,17 @@ public Object call() {
return new File(docsDir, "aggregateJavadoc");
}
});
aggregateJavadoc.setClasspath(classpathConfiguration);
aggregateJavadoc.setClasspath(aggregateClasspath);
});

project.allprojects(subproject -> {
subproject.getPlugins().withType(JavaPlugin.class, jp -> {

SourceSet main = subproject.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName("main");
Configuration compileClasspath = subproject.getConfigurations().getByName(main.getCompileClasspathConfigurationName());
Configuration javadocClasspathProvider = subproject.getConfigurations().maybeCreate("javadocClasspathProvider");
javadocClasspathProvider.extendsFrom(compileClasspath);

Map<String, String> dep = new HashMap<>();
dep.put("path", subproject.getPath());
dep.put("configuration", javadocClasspathProvider.getName());
classpathConfiguration.getDependencies().add(project.getDependencies().project(dep));
AggregateJavadocClientPlugin clientPlugin = subproject.getPlugins().apply(AggregateJavadocClientPlugin.class);
aggregateClasspath.from(clientPlugin.getJavadocClasspath());

aggregateJavadoc.configure(aj -> {
SourceSet main = subproject.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName("main");
Javadoc javadoc = subproject.getTasks().named(main.getJavadocTaskName(), Javadoc.class).get();

aj.source(javadoc.getSource());
Expand Down

0 comments on commit f0dd63f

Please sign in to comment.