Can't link to JDK10 in Javadoc comments

前端 未结 3 1534
太阳男子
太阳男子 2021-02-01 05:37

After upgrading from Java 9 to 10, links to the JDK no longer work when generating documentation with the Javadoc tool (e.g., for a file importing java.util.Optional

相关标签:
3条回答
  • 2021-02-01 06:02

    ...Maven committer here.

    Appropriate bits have been added to Maven Javadoc Plugin in master already, but that won't help due to a bug in javadoc(1) in Java 11. See MJAVADOC-561 for details. The broken links can only be fixed by Oracle.

    Edit: The fix is scheduled for Java 11.0.2 by Oracle.

    0 讨论(0)
  • 2021-02-01 06:15

    There are two parts to this.

    1. In JDK 10, the format and name of the file have changed, to better support modules. The new name is "element-list" and the change in format allows the javadoc tool to know what modules are present in an API as well as what packages.

    2. The copy of the API that is posted at https://docs.oracle.com/javase/10/docs/api/overview-summary.html seems to be blocking the "element-list" file, giving a 404. That needs to be investigated and fixed.

    Note that you will need to use a JDK 10 version of javadoc to point to the JDK 10 API. The latest version of the tool understands both element-list (for docs about modules) and package-list (for docs about packages (i.e. no modules)).

    0 讨论(0)
  • 2021-02-01 06:22

    My workaround for the moment is to point javadoc.exe at a local package-list using the offlineLinks option of the Maven Javadoc plugin (which corresponds to the linkoffline option of the Javadoc tool). I added the following to the configuration section for the plugin:

    <detectJavaApiLink>false</detectJavaApiLink>
    <offlineLinks>
        <offlineLink>
            <url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
            <location>${project.basedir}</location>
        </offlineLink>
    </offlineLinks>
    

    And I added <maven.compiler.release>10</maven.compiler.release> to the properties section of my pom.xml so that I could use ${maven.compiler.release} in the value for the url. (That makes the source and target compiler options redundant, but IntelliJ doesn't seem to understand release when importing Maven projects, so I kept them.)

    I created a text file named package-list (no file extension) and put it in the root directory of the project (hence ${project.basedir} for the location, which is where it will look for package-list). That file looks like this:

    java.lang
    java.util
    java.util.concurrent
    java.util.function
    java.util.stream
    

    It only needs the packages that you're trying to link to. I also tried naming the file element-list and following the format that javadoc.exe uses for modularized projects, like so:

    module:java.base
    java.lang
    java.util
    java.util.concurrent
    java.util.function
    java.util.stream
    

    But that didn't work (Javadoc successfully generated, but no JDK links, as before). It complained that it couldn't find package-list.

    So, once again, the relevant bits of the pom.xml:

    <properties>
        <maven.compiler.release>10</maven.compiler.release> <!--release makes source and target-->
        <maven.compiler.source>10</maven.compiler.source> <!--redundant, but IntelliJ doesn't-->
        <maven.compiler.target>10</maven.compiler.target> <!--use release when importing-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.1</version> <!--update dependency for Java 10 compatibility-->
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <detectJavaApiLink>false</detectJavaApiLink>
                    <offlineLinks>
                        <offlineLink>
                            <url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
                            <location>${project.basedir}</location>
                        </offlineLink>
                    </offlineLinks>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </build>
    
    0 讨论(0)
提交回复
热议问题