问题
Exit code: 1 - javadoc: error - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/11/docs/api/ are in named modules.
Has anyone been able to make javadoc work without having to change the source version to 1.8 (as suggested in other forums)? I'm using JDK v11.0.5 and the issue still present (also with JDK 12+).
Edit: This error originated from maven and thrown by the maven-javadoc-plugin. I have not been able to make it work for JDK 11+ even with the <source>8</source>
configuration.
回答1:
There was a significant breaking change since Java 9 for using Doclet API
JEP 221: Simplified Doclet API
Replaces the old Doclet API with a new simplified API that leverages other standard, existing APIs.The standard doclet has been rewritten to use the new Doclet APIThe existing API and old standard doclet are available, but have not been updated to support new language features, such as modules
Old API is using com.sun.javadoc package
The Doclet API (also called the Javadoc API) provides a mechanism for clients to inspect the source-level structure of programs and libraries, including javadoc comments embedded in the source.
You can try using the new Doclet API, see examples
public class BasicDoclet implements Doclet { @Override public void init(Locale locale, Reporter reporter) { } @Override public String getName() { // For this doclet, the name of the doclet is just the // simple name of the class. The name may be used in // messages related to this doclet, such as in command-line // help when doclet-specific options are provided. return getClass().getSimpleName(); }
回答2:
javadoc produces links to packages you use, e.g. to classes documented in .../javase/11/docs/api
. While your comments are in an unnamed module, the targets are not, and javadoc can't combine those two. It produces either a package-list
or an element-list
file, so you can't mix unnamed modules (packages) with named modules.
I didn't find a way to limit the links that javadoc tries to produce; so you may have to use modules for your own project. This seems ridiculous to me, just to make javadoc happy. I guess this is just one of the reasons that so many people stick to Java 8.
来源:https://stackoverflow.com/questions/58836862/jdk-11-and-javadoc