2828public 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