How to avoid duplicate forking when generating aggregated javadoc in a multimodule project
Asked Answered
I

1

9

I am trying to configure a Maven multimodule project to produce a distribution zip via the assembly plugin, which should include aggregated javadoc for all submodules in the project.

The project structure is (simplified, in reality there's about 20 modules):

Project X Core
 +- pom.xml (1)
 +- module-A 
 |    +- pom.xml (2)
 +-module-B 
 |    +- pom.xml (3)
 +-assembly
      +- pom.xml (4)

where assembly is the submodule that produces the distribution zip. The root pom lists all submodules as modules, each submodule's pom has, in turn, the root pom as its parent. The assembly plugin is bound to the package phase. All of this works fine.

The problem occurs when I try to create aggregated javadoc (not javadoc jars, but a directory with html), to include in the assembly. To achieve this, I have configured the maven-javadoc-plugin as a build plugin in the root pom, as follows:

   <build>
    <plugins>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <encoding>utf8</encoding>
                <quiet>true</quiet>
                <links>
                    <link>http://docs.oracle.com/javase/6/docs/api/</link>
                </links>
            </configuration>
            <executions>
                <execution>
                    <id>create-javadoc</id>
                    <phase>package</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

In addition, I have configured my assembly descriptor, in the assembly submodule, to include a fileSet with the javadocs, picked from the target dir of its parent project:

    <fileSet>
        <directory>../target/site/apidocs</directory>
        <outputDirectory>docs/apidocs</outputDirectory>
    </fileSet>

The problem I face with this setup is this: I see the following output when running mvn package:

[INFO] Reactor Build Order:
[INFO] 
[INFO] Project X Core
[INFO] Project X: module A
[INFO] Project X: module B
[INFO] Project X: assembly
[INFO] ------------------------------------------------------------------------
[INFO] Building Project X Core 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-core ---
[INFO] 
[INFO] --- animal-sniffer-maven-plugin:1.13:check (default) @ projectX-core ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java16:1.0
[INFO] 
[INFO] >>> maven-javadoc-plugin:2.10.1:aggregate (create-javadoc) > generate-sources @ projectX-core >>>
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Core 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-core ---
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: module A 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-modA ---
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: module B 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-modB ---
Downloading: https://example.org/repositories/snapshots/org/example/project/projectX-modB/1.0.0-SNAPSHOT/modB-1.0.0-20141121.022310-7.jar
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: Assembly 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Downloading: https://example.org/repositories/snapshots/org/example/project/projectX-modC/1.0.0-SNAPSHOT/maven-metadata.xml
2/2 KB    
     (snip for brevity)
[INFO] ------------------------------------------------------------------------
[INFO] Building Project X: module A 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-modA ---
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ projectX-modA ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jeen/Projects/projectX/modA/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ projectX-modA ---
[INFO] Compiling 52 source files to /Users/jeen/Projects/projectX/modA/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ projectX-modA ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jeen/Projects/projectX/modA/util/src/test/resources
[INFO] 
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ projectX-modA ---
[INFO] Building jar: /Users/jeen/Projects/projectX/modA/target/modA-1.0.0-SNAPSHOT.jar
[INFO] 
[INFO] >>> maven-javadoc-plugin:2.10.1:aggregate (create-javadoc) > generate-sources @ projectX-modA >>>
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Core 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-core ---
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Module A 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ projectX-modA ---
[INFO]                                                                         
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking ProjectX Module B 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.....

This is just a snippet, but these "Forking" messages are repeated a great number of times for each submodule (in fact, in reality about 60 times per module). This worries me: it looks as if there is an awful lot of duplicate work going on. A second thing that worries me is that it apparently downloads remote snapshots of artifacts that are part of the current reactor (see the 'Downloading' messages in the snippet above). I should point out that despite all these duplicate messages, the goal is achieved: the aggregate javadoc is produced, and is included in the assembly.

So, the question is really: what (if anything) am I doing wrong? Should I just ignore these repeating "Forking" messages and the snapshot downloads, or are they an indication of an incorrect setup? If the latter, does anybody have an idea how I should tweak the setup to get this to work correctly?

FWIW I have already tried several alternative configurations, including moving the javadoc plugin config to the assembly submodule, but none of it gave me the expected results.

I've tried to keep it brief and to the point, if additional info is needed let me know.

Running Maven 3.2.3, by the way.

Intersect answered 14/1, 2015 at 4:2 Comment(0)
I
3

I seem to have found the answer to my own question.

The problem is in the javadoc plugin configuration. Because the plugin is in the aggregator project's build section, it gets inherited by the submodules (which then each execute it in turn, apparently).

Simply making sure the plugin does not get inherited fixed the issue:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <inherited>false</inherited>
        ...
Intersect answered 16/1, 2015 at 3:7 Comment(2)
i am having this same problem. when my multimodule maven build comes to the site gen it says (in logs) "preparing 'aggregate' report requires 'generate-sources' forked phase execution" and there comes that "forking" message with ">>>>>>>" ...even though i have tried your solution. Any other ideas? I also tried this: maven.apache.org/plugins/maven-javadoc-plugin/examples/…Asseveration
fyi here is my related question #47199646Asseveration

© 2022 - 2024 — McMap. All rights reserved.