javamavenjavadocjava-modulemaven-javadoc-plugin

Javadoc for JPMS modules when module name is different from artifactId


I have a sample project with two jpms modules. It is a maven project with one parent and two child modules.

A parent pom:

...
<modules>
    <module>foo.api</module>
    <module>foo.impl</module>
</modules>
...

API module pom:

...
<groupId>com.foo</groupId>
<artifactId>foo.api</artifactId>
...

API module-info:

module com.foo.api {
    requires org.slf4j;
    exports com.foo.api;
}

These are my settings for maven-javadoc-plugin (in parent pom):

   <reporting>
         <excludeDefaults>true</excludeDefaults>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.3.0</version>
                <reportSets>
                  <reportSet>
                    <reports>
                      <report>javadoc-no-fork</report>
                      <report>test-javadoc-no-fork</report>
                    </reports>
                  </reportSet>
                </reportSets>
                <configuration>
                    <doclint>none</doclint>
                    <dependencySourceIncludes>
                       <dependencySourceInclude>com.foo:${project.artifactId}</dependencySourceInclude>
                    </dependencySourceIncludes>
                    <doctitle>Title - ${project.version}</doctitle>
                    <includeDependencySources>false</includeDependencySources>
                    <windowtitle>Title</windowtitle>
                    <additionalJOptions>
                        <additionalJOption>--no-module-directories</additionalJOption>
                    </additionalJOptions>
                </configuration>
              </plugin>
        </plugins>
    </reporting>

And when I run mvn javadoc:javadoc I get:

Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:javadoc (default-cli) on project foo.api: An error has occurred in Javadoc report generation: 
Exit code: 1 - error: module not found: com.foo.api

Could anyone say how to fix it?


Solution

  • I found the solution. In case of modules, javadoc requires a compiles module descriptor, so it is necessary to do mvn compile javadoc:javadoc instead of mvn javadoc:javadoc