JDK 11+ and Javadoc
Asked Answered
T

7

68
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.

Tranship answered 13/11, 2019 at 12:12 Comment(4)
Related bugs.openjdk.java.net/browse/JDK-8212233Skiff
I think this question needs some more details. Do you use maven? Do you use or have you tried to use modules in your project?Feticide
@rü- you're right, I have updated the post, thanks. Yes, I am using maven with a multi-module setup.Tranship
With the latest javadoc plugin it is working for me. I originally had source set to 8 and it was failing. Given your observation I'm guessing this was fixed in a later version I'm using 3.2.0 currentlyIrrelevant
C
52

As suggested in OpenJDK issue tracker this can be worked around with defining source on Javadoc plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <configuration>
        <source>8</source>
    </configuration>
</plugin>
Curtsey answered 20/2, 2020 at 14:42 Comment(6)
Probably, you didn't read the question completely. OP has clearly mentioned: Has anyone been able to make javadoc work without having to change the source version to 1.8Rahm
it works for me. I use: <configuration> <source>${java.version}</source> </configuration> and in properties it's java 11. I just had to specify the version for some reason.Synchrocyclotron
How can you do this in Gradle?Pentangular
When using JDK 8, I set it to 1.8, not 8. Perhaps both work.Urbana
Also suggested as the solution in bugs.java.com/bugdatabase/view_bug.do?bug_id=8212233Ceram
I used version 11 on my build, and it solved the problem.Griffie
T
31

Adding <detectJavaApiLink>false</detectJavaApiLink> to the Maven javadoc pluging configuration fix the error

Tether answered 19/5, 2020 at 6:4 Comment(1)
This worked for me using AdoptOpenJDK 11.0.8 (2020-07-14) on a Mac. I already had <source>8</source> set and it was working for other versions of JDK 11, but not for 11.0.8.Selfforgetful
S
24

I needed the bit from Carlos Santos to make this really work. The complete config that incorporates his answer is:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <configuration>
    <source>8</source>
    <detectJavaApiLink>false</detectJavaApiLink>
  </configuration>
</plugin>
Sabotage answered 18/8, 2020 at 19:39 Comment(1)
Thanks. Even without <source>8</source>, the above snippet still works for me, in combination with <properties>maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target></properties>Osteoclasis
S
6

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.

Salutary answered 18/11, 2019 at 12:13 Comment(2)
I fully agree. Further it would be helpful if maven-javadoc-plugin would tell which modules are unnamed so you can trace down the problem in a very large project. Also it could offer an option to ignore unnamend modules in aggregation. This does not seem to be the case: maven.apache.org/plugins/maven-javadoc-plugin/…Cycloparaffin
@Jörg Yes, this is all super-annoying isn't it?Rossini
C
3

I was able to get my own project to work by using a new version of the compiler plugin and setting the release property to 8.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
</plugin>

<properties>
    <maven.compiler.release>8</maven.compiler.release>
</properties>
Culottes answered 8/12, 2020 at 21:16 Comment(0)
S
-2

I was facing the same issue. I was using Java 11.0.3 and org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar. Updating the maven-javadoc-plugin version to 3.2.0 worked perfectly for me.

Siret answered 3/8, 2020 at 8:25 Comment(3)
I am using maven-javadoc-plugin version 3.2.0 and get exactly this error. So that does not fix the issue.Cycloparaffin
@Jörg Which Java version are you using?Siret
My Java version is 11.0.5+10Cycloparaffin
P
-3

We can use <detectOfflineLinks>false</detectOfflineLinks> in the configuration.

Polyamide answered 3/12, 2020 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.