assertj: Cannot link to assertj-core JavaDoc due to JPMS

Summary

The JavaDocs for AssertJ appear to be being built under Java 8, which means the Java-9 module-info.class descriptor is not being taken into account, resulting in a JavaDoc being generated that behaves as if it were defined in the unnamed module (i.e. with no module name prefix on the path).

When linking another project to these JavaDocs for a JPMS-enabled project, maven-javadoc-plugin appears to be unable to link correctly.

Example

Under Maven 3.8.5, maven-javadoc-plugin 3.3.2, assertj-core 3.22.0, java-release.version 11:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>${maven-javadoc-plugin.version}</version>
  
  <configuration>
    <additionalOptions>
      <option>--override-methods=detail</option>
      <option>-version</option>
    </additionalOptions>
    <source>${java-release.version}</source>
    <links>
      <link>https://javadoc.io/doc/org.assertj/assertj-core/${assertj.version}</link>
    </links>
  </configuration>
  
  <executions>
    <execution>
      <id>default-javadoc</id>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Running under JDK 11, JDK 12, JDK 13, and JDK 14; Maven will fail with the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.3.2:jar (default-javadoc) on project java-compiler-testing: MavenReportException: Error while generating Javadoc: 
[ERROR] Exit code: 1 - javadoc: error - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[ERROR] 
[ERROR] Command line was: /opt/hostedtoolcache/Java_Zulu_jdk/12.0.2-3/x64/bin/javadoc @options @packages @argfile
[ERROR] 
[ERROR] Refer to the generated Javadoc files in '/home/runner/work/java-compiler-testing/java-compiler-testing/java-compiler-testing/target/apidocs' dir.
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Under JDK 15 and above, this just spams a large number of warnings instead:

 23 warnings
[WARNING] Javadoc Warnings
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.
[WARNING] javadoc: warning - The code being documented uses modules but the packages defined in https://javadoc.io/doc/org.assertj/assertj-core/3.22.0/ are in the unnamed module.

This effectively prevents a project from being able to depend and extend parts of assertj while still providing valid documentation. This applies to both the hosted JavaDoc you link to from the assertj page, and the generated JavaDoc on javadoc.io.

For example, if I had a library with this API defined in it (not correct code, but you get the idea):

module org.example.me.compilerassertions {
  requires org.assertj.core;
  exports org.example.me;
}
// extending AbstractObjectAssert should link the inherited methods from the assertj-core javadocs
class CompilerAssertions extends AbstractObjectAssert<CompilerAssertions, Compilation> {
  private Compilation compilation;
  
  ...
  
  /**
   * Assert compilation succeeded.
   */
  public CompilerAssertions isSuccessful() {
    assertThat(compilation.isSuccess())
        .withFailMessage("Expected compilation to succeed, but it failed")
        .isTrue();
    return myself;
  }
}

Possible solution (?)

One possible solution may be to run JavaDoc from Java 9 or newer to allow module descriptors to be created (assuming the task is run from a Java 8 JVM). This would require anyone linking to these docs from JDK 8 to use a modified path. Hopefully most projects that are actively maintained should be targeting JDK 11 and newer now (even if they still support Java 8 as a minimum), meaning they may also come across this issue if they are in the same scenario. Java 8-only projects may have linking issues from JavaDoc, but this will eventually be an issue anyway once Java 8 extended support ends.


Relates to:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks! Once the JAR is available can you let me know and I’ll give it a whirl.

Thanks for the work on this!

@ascopes This should have been addressed by #3771, as now we produce modular Javadoc.

4.0.0-M1 will be published soon™, so you should be able to try it out (in case you don’t want to build the project locally).

Because of this, I’m closing the issue, but please let us know if something doesn’t work as expected.

Might have to be in the morning; will set myself a reminder to take a look.

Most recent one I can spot in the wild is at https://github.com/ascopes/jct/runs/6440094969?check_suite_focus=true#step:4:84 which is a Maven project at https://github.com/ascopes/jct. Haven’t had a more recent build since I have been working on a rewrite on a side branch that broke a lot of stuff, but I believe there is a cronjob to rerun that at midnight UTC if a more recent run is needed.

It isn’t exactly “minimal” so I will see what I can do in the morning, and get back to you!

Cool, if you need any help verifying the issue with an existing project, feel free to shout and I can give it a try!

Thanks!

For now, I’ve just allowed warnings to pass. I’ve had several issues with javadoc.io 503ing and 504ing in the past during deployments which has caused my builds to fall over. This is really useful to know though.

@ascopes the root cause seems to be the multi-release setup for AssertJ 3, also described in JDK-8240169.

Under JDK 15 and above, this just spams a large number of warnings instead

As far as I understand from the JDK bug, having warnings is the intended behavior with JDK 15 or newer, when:

  • Modular jars link to non-modular documentation
  • Non-modular jars link to modular documentation

Creating and publishing modular documentation seems a non-trivial change in our multi-release setup since there is no out-of-the-box support by the maven-javadoc-plugin. I tried composing a custom configuration to demonstrate it locally but I couldn’t make it work.

Even if we would publish modular documentation, warnings would still be triggered in certain cases so it isn’t yet the ultimate solution.

This effectively prevents a project from being able to depend and extend parts of assertj while still providing valid documentation. This applies to both the hosted JavaDoc you link to from the assertj page, and the generated JavaDoc on javadoc.io.

My suggestion for AssertJ 3 would be:

  • Use JDK 15 or newer
  • Don’t let the build fail with Javadoc warnings

Eventually, this will be addressed by AssertJ 4.

Thank you, @ascopes. We’ll try to have another look this week.

@ascopes I’m struggling to put together a reproducible example and a suitable test accordingly. Would you mind sharing a small Maven project to reproduce this issue?

I’m afraid the fix will not be part of 3.23.0 as we plan to have this version very soon, but we may ship it in a later bugfix release in case it can be finalized quickly.

Let’s check that the javadoc is generated with good css rendition if we use a newer java version, I checked for java 11 it works fine but not on java 17.

I’m not sure about the compatibility with Java 8 projects, but we should be able to have integration tests and verify that everything works correctly.