在多模块项目中生成聚合 javadoc 时如何避免重复分叉

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

我正在尝试配置 Maven 多模块项目以通过程序集插件生成分发 zip,其中应包括项目中所有子模块的聚合 javadoc。

项目结构是(经过简化,实际上大约有 20 个模块):

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

其中 assembly 是生成分发 zip 的子模块。根 pom 将所有子模块列为模块,每个子模块的 pom 依次将根 pom 作为其父级。程序集插件绑定到 package 阶段。所有这一切都很好。

当我尝试创建聚合 javadoc( 不是 javadoc jar,而是包含 html 的目录)以包含在程序集中时,会​​出现问题。为此,我在根pom中配置了maven-javadoc-plugin作为构建插件,如下:

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

此外,我在程序集子模块中配置了我的程序集描述符,以包含一个带有 javadoc 的文件集,从其父项目的目标目录中选取:

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

我在这个设置中遇到的问题是:当 运行 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] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.....

这只是一个片段,但是这些 "Forking" 消息在每个子模块中重复了很多次(事实上,每个模块实际上重复了大约 60 次)。这让我很担心:看起来好像正在进行大量重复工作。让我担心的第二件事是,它显然下载了属于当前反应堆一部分的工件的远程快照(请参阅上面代码段中的 'Downloading' 消息)。我应该指出,尽管有所有这些重复的消息,但目标已经实现:生成了聚合 javadoc,并包含在程序集中。

所以,真正的问题是:我做错了什么(如果有的话)?我应该忽略这些重复的 "Forking" 消息和快照下载,还是它们表明设置不正确?如果是后者,有人知道我应该如何调整设置才能使其正常工作吗?

FWIW 我已经尝试了几种替代配置,包括将 javadoc 插件配置移动到程序集子模块,但是 none 它给了我预期的结果。

我尽量保持简明扼要,如果需要更多信息,请告诉我。

运行 Maven 3.2.3,顺便说一句。

我似乎找到了我自己问题的答案。

问题出在 javadoc 插件配置中。因为插件位于聚合器项目的构建部分,所以它被子模块继承(显然,每个子模块依次执行它)。

只需确保插件不会被继承即可解决问题:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <inherited>false</inherited>
        ...