使用 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 編譯器插件的配置時,儘管該警告確實出現在僅針對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>