使用 maven-javadoc-plugin 生成 JavaDoc Java 存档资源时,显示以下警告:
[WARNING] javadoc: warning - Error reading file: /maven-javadoc-example/target/javadoc-bundle-options/package-list
我已经检查了 Apache Maven JavaDoc 插件 mojo 页面:
https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html
我已经用标志检查了调试信息-X
:
mvn javadoc:jar@main-javadoc -X
我已经检查了 Oracle Java 工具页面(JDK12):
https://docs.oracle.com/en/java/javase/12/tools/javadoc.html
我怀疑这与我有一个 Maven 项目设置有关,这样我就可以针对 JDK8 编译生产代码,同时仍然能够针对 JDK11 运行/编译测试代码(当我删除 Maven Compiler 插件的配置时,警告停止,尽管警告确实出现在仅针对 JDK11 编译的其他项目中)。
下面是一个最小的 Apache Maven POM 来重现此警告(请注意,源路径中必须至少有一个 Java 类源):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.superuser.maven</groupId>
<artifactId>maven-javadoc-example</artifactId>
<version>1.0.0</version>
<properties>
<!-- Settings: maven-resource-plugin -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Settings: maven-compiler-plugin -->
<maven.compiler.main-jdk>8</maven.compiler.main-jdk>
<maven.compiler.test-jdk>11</maven.compiler.test-jdk>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>main-compile</id>
<phase>compile</phase>
<configuration>
<source>${maven.compiler.main-jdk}</source>
<target>${maven.compiler.main-jdk}</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>-Xlint:all,-processing,-cast,-serial,-try</arg>
</compilerArgs>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>${maven.compiler.test-jdk}</release>
</configuration>
</execution>
</executions>
<configuration>
<source>${maven.compiler.test-jdk}</source>
<target>${maven.compiler.test-jdk}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>main-javadoc</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<sourceFileExcludes>module-info.java</sourceFileExcludes>
</configuration>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
<failOnWarnings>false</failOnWarnings>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
有没有办法解决这个警告,仍然会有一个 Maven 模块针对(可能)两个不同的 JDK API 编译生产代码和测试代码?
编辑:
- 更改 JDK 和/或 %JAVA_HOME% 不能解决此问题。
- 添加/删除 module-info.java 文件不能解决此问题。
- 添加了怀疑针对两个不同的 JDK API 进行编译可能是造成此问题的原因。
- 修复了执行定义,以便 JavaDoc 在针对 JDK8 进行编译/打包/javadoc 时不会出现错误。
答案1
对我有用的是删除来源和目标从 Maven 编译器插件通用配置中删除标签,并将它们放置在新的执行配置中。
这是POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.superuser.maven</groupId>
<artifactId>maven-javadoc-example</artifactId>
<version>1.0.0.Final</version>
<properties>
<!-- Settings: maven-resource-plugin -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Settings: maven-compiler-plugin -->
<maven.compiler.main-jdk>8</maven.compiler.main-jdk>
<maven.compiler.test-jdk>11</maven.compiler.test-jdk>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
<configuration>
<release>${maven.compiler.test-jdk}</release>
</configuration>
</execution>
<execution>
<id>main-compile</id>
<phase>compile</phase>
<configuration>
<release>${maven.compiler.test-jdk}</release>
</configuration>
</execution>
<execution>
<id>main-compile-jdk8</id>
<phase>none</phase>
<configuration>
<source>${maven.compiler.main-jdk}</source>
<target>${maven.compiler.main-jdk}</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>${maven.compiler.test-jdk}</release>
</configuration>
</execution>
</executions>
<configuration>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>-Xlint:all,-processing,-cast,-serial,-try</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>main-javadoc</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<sourceFileExcludes>module-info.java</sourceFileExcludes>
</configuration>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
<failOnWarnings>false</failOnWarnings>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>