例如,考虑以下目录结构:
Project
|-- pom.xml
|-- Module1
| `-- pom.xml
| `-- Module 2
| `-- pom.xml
| `-- Module 3
| `-- pom.xml
|-- Module4
| `-- pom.xml
`-- Module5
`-- pom.xml
自 3.1.0 以来,聚合发生了一些变化。它将在每个级别生成汇总报告。要仅在根级别获取聚合项目,您需要像这样配置 pom:
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<reportSets>
<reportSet>
<id>aggregate</id>
<inherited>false</inherited>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
<reportSet>
<id>default</id>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
...
</reporting>
...
</project>
<aggregate/>参数不包括使用build-helper:add-source定义的生成源目录。在这种情况下,您需要使用聚合目标和测试聚合目标。您可以在 <build/> 元素(使用 <execution/> 标签)或 <reporting/> 元素(使用 <reportSet/> 标签)中定义这些目标,如下所示。有关更多信息,请参阅选择性 Javadocs 报告页面。
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>site</phase>
<configuration>
<!-- Specific configuration for the aggregate report -->
...
</configuration>
</execution>
...
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<reportSets>
<reportSet>
<id>non-aggregate</id>
<configuration>
<!-- Specific configuration for the non aggregate report -->
...
</configuration>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate</id>
<configuration>
<!-- Specific configuration for the aggregate report -->
...
</configuration>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
...
</reportSets>
</plugin>
...
</plugins>
</reporting>
...
</project>
从 Java 9 开始,可以将模块描述符添加到您的项目中,这可能会对生成的报告产生影响。请注意,命名和未命名模块不可能混合使用。理想情况下,每个 Maven 模块都有一个 Java 模块描述符,但这并不总是可能的,例如由于依赖项的拆分包。在这种情况下,您必须有一个包含META-INF/MANIFEST.MF的 jar,其中包含Automatic-Module-Name条目。换句话说:确保调用包 javadoc:aggregate,因为清单文件仅从 jar 中读取,而不是从文件夹中读取。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.foo.bar</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
有时,自动模块需要导入命名模块。例如,
error: package org.w3c.dom is not visible
(package org.w3c.dom is declared in module java.xml, but module foobar does not read it)
可以通过在插件配置中添加相关的 --add-modules 选项来解决:
<additionalOptions>
<option>--add-modules</option>
<option>java.xml</option>
</additionalOptions>
Javadoc 插件包含几个与聚合器项目一起使用的聚合目标。以下是所有汇总目标的完整列表: