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

Rafael Ibasco
  • 1,048
  • 2
  • 13
  • 19

8 Answers8

35

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>
Roman Grigoriadi
  • 1,552
  • 11
  • 8
23

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

Carlos Saltos
  • 989
  • 11
  • 12
  • 2
    This worked for me using AdoptOpenJDK 11.0.8 (2020-07-14) on a Mac. I already had `8` set and it was working for other versions of JDK 11, but not for 11.0.8. – Doug Noel Aug 06 '20 at 12:49
16

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>
Scott Seely
  • 677
  • 4
  • 6
  • 1
    Thanks. Even without `8`, the above snippet still works for me, in combination with `maven.compiler.source>1111` – eigenfield Nov 06 '20 at 04:15
4

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.

rü-
  • 1,657
  • 11
  • 29
  • 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: https://maven.apache.org/plugins/maven-javadoc-plugin/aggregate-mojo.html – Jörg Oct 23 '20 at 07:22
2

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>
Robin
  • 23,156
  • 4
  • 47
  • 57
0

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.

0

I have this problem because I used module-info.test approach to unit testing with Java 9 modules.

Simply excluding javadoc generation for tests fixed the issue for me.

                    <reportSet>
                        <reports>
                            <report>javadoc</report>
                            <report>test-javadoc</report>
                        </reports>
                    </reportSet>

Simply remove test-javadoc report.

csharpfolk
  • 3,778
  • 20
  • 26
-2

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

Boken
  • 3,207
  • 9
  • 25
  • 31