Skip to content

Commit d06baa6

Browse files
committed
Use aggregateJavadocClasspath Configuration
Closes gh-4
1 parent 93e4848 commit d06baa6

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

README.adoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ plugins {
5050
}
5151
----
5252

53+
=== aggregateJavadocClasspath Configuration
54+
55+
This will create a `Configuration` named `aggregateJavadocClasspath` that is used to determine the classpath for the <<aggregateJavadoc Task>>.
56+
This `Configuration` is defaulted to include all projects that have the `io.spring.javadoc` applied to it.
57+
5358
=== aggregateJavadoc Task
5459

5560
This will create a task named `aggregateJavadoc` of type https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html[`Javadoc`].
@@ -71,7 +76,7 @@ You may apply to any module, but you will need to adjust the task accordingly.
7176

7277
=== Customizing Aggregated Projects
7378

74-
You can customize which projects' Javadoc is aggregated by explicitly providing projects for the `implementation` configuration.
79+
You can customize which projects' Javadoc is aggregated by explicitly providing projects for the `aggregateJavadocClasspath` configuration.
7580
For example, the following explicitly aggregates `module1` and `module2` regardless of which projects have `io.spring.javadoc` applied to them.
7681

7782
[source,groovy]
@@ -81,8 +86,8 @@ plugins {
8186
}
8287
8388
dependencies {
84-
implementation project(':module1')
85-
implementation project(':module3')
89+
aggregateJavadocClasspath project(':module1')
90+
aggregateJavadocClasspath project(':module3')
8691
}
8792
----
8893

src/integTest/resources/javadoc/custom-projects/aggregator/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ plugins {
33
}
44

55
dependencies {
6-
implementation project(':module1')
7-
implementation project(':module3')
6+
aggregateJavadocClasspath project(':module1')
7+
aggregateJavadocClasspath project(':module3')
88
}

src/main/java/io/spring/gradle/javadoc/AggregateJavadocPlugin.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,22 @@
2828
public class AggregateJavadocPlugin implements Plugin<Project> {
2929
public static final String AGGREGATE_JAVADOC_TASK_NAME = "aggregateJavadoc";
3030

31+
public static final String AGGREGATE_JAVADOC_CLASSPATH_CONFIGURATION_NAME = "aggregateJavadocClasspath";
32+
3133
@Override
3234
public void apply(Project project) {
3335
project.getPlugins().apply(JavaPlugin.class);
34-
aggregatedDependencies(project);
35-
Configuration sourcesPath = sourcesPath(project);
36-
aggregatedJavadoc(project,sourcesPath);
36+
Configuration aggregatedConfiguration = aggregatedConfiguration(project);
37+
Configuration sourcesPath = sourcesPath(project, aggregatedConfiguration);
38+
aggregatedJavadoc(project,sourcesPath, aggregatedConfiguration);
3739
}
3840

39-
private void aggregatedDependencies(Project project) {
41+
private Configuration aggregatedConfiguration(Project project) {
4042
ConfigurationContainer configurations = project.getConfigurations();
41-
Configuration implementation = configurations
42-
.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME);
43-
implementation.defaultDependencies(new Action<DependencySet>() {
43+
Configuration aggregatedConfiguration = configurations
44+
.maybeCreate(AGGREGATE_JAVADOC_CLASSPATH_CONFIGURATION_NAME);
45+
configurations.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(aggregatedConfiguration);
46+
aggregatedConfiguration.defaultDependencies(new Action<DependencySet>() {
4447
@Override
4548
public void execute(DependencySet defaultDependencies) {
4649
project.getGradle().getRootProject().subprojects(new Action<Project>() {
@@ -58,17 +61,18 @@ public void execute(JavadocPlugin javadoc) {
5861
});
5962
}
6063
});
64+
return aggregatedConfiguration;
6165
}
6266

63-
private Configuration sourcesPath(Project project) {
67+
private Configuration sourcesPath(Project project, Configuration aggregatedConfiguration) {
6468
ConfigurationContainer configurations = project.getConfigurations();
6569
return configurations.create("sourcesPath", new Action<Configuration>() {
6670
@Override
67-
public void execute(Configuration config) {
68-
config.setCanBeResolved(true);
69-
config.setCanBeConsumed(false);
70-
config.extendsFrom(configurations.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));
71-
config.attributes(new Action<AttributeContainer>() {
71+
public void execute(Configuration sourcesPath) {
72+
sourcesPath.setCanBeResolved(true);
73+
sourcesPath.setCanBeConsumed(false);
74+
sourcesPath.extendsFrom(aggregatedConfiguration);
75+
sourcesPath.attributes(new Action<AttributeContainer>() {
7276
@Override
7377
public void execute(AttributeContainer attributes) {
7478
ObjectFactory objects = project.getObjects();
@@ -80,7 +84,7 @@ public void execute(AttributeContainer attributes) {
8084
Attribute.of("org.gradle.docselements", String.class), "sources");
8185
}
8286
});
83-
config.outgoing(new Action<ConfigurationPublications>() {
87+
sourcesPath.outgoing(new Action<ConfigurationPublications>() {
8488
@Override
8589
public void execute(
8690
ConfigurationPublications publications) {
@@ -100,16 +104,15 @@ public void accept(File file) {
100104
});
101105
}
102106

103-
private void aggregatedJavadoc(Project project, Configuration sourcesPath) {
107+
private void aggregatedJavadoc(Project project, Configuration sourcesPath, Configuration aggregatedConfiguration) {
104108
project.getTasks().create(AGGREGATE_JAVADOC_TASK_NAME, Javadoc.class, new Action<Javadoc>() {
105109
@Override
106110
public void execute(Javadoc javadoc) {
107111
javadoc.setGroup("Documentation");
108112
javadoc.setDescription("Generates the aggregate Javadoc");
109113
ConfigurationContainer configurations = project.getConfigurations();
110-
Configuration compile = configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
111114
javadoc.setSource(sourcesPath);
112-
javadoc.setClasspath(compile);
115+
javadoc.setClasspath(aggregatedConfiguration);
113116
}
114117
});
115118
}

0 commit comments

Comments
 (0)