1

I have read everything I can find on solving this and my attempts still fail. The best I can do is to get the Javadoc of exactly one module to show up--the last one built. (For now, I'm not trying to bundle Javadoc into any JARs. I'm also not trying to do anything "site".) I just want to put Javadoc for easy access into a subdirectory under the project root.

Here's what's in my parent pom.xml:

<build>
  <plugins>
    .
    .
    .
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>3.2.0</version>
      <configuration>
        <noqualifier>all</noqualifier>
        <reportOutputDirectory>${user.dir}/documents</reportOutputDirectory>
        <destDir>javadoc</destDir>
      </configuration>
      <executions>
        <execution>
          <id>attach-javadocs</id>
          <phase>package</phase>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

What I'm putting into subordinate pom.xml files is identical to the above except for

          <goals>
            <goal>javadoc</goal>
          </goals>

I have played with replacing the <execution> in the parent and sometimes subordinate pom.xml files with:

        <execution>
          <id>aggregate</id>
          <goals>
            <goal>aggregate</goal>
          </goals>
        </execution>

but it makes no difference.

Russ Bateman
  • 18,333
  • 14
  • 49
  • 65

1 Answers1

1

I think the following configuration is the reason your reports get overwritten:

<configuration>
  <reportOutputDirectory>${user.dir}/documents</reportOutputDirectory>
</configuration>

All module builds will be written to the same directory, hence overwriting the previous build.

The solution is to use the default output directory and configure the output directory for the aggregated javadoc instead. This way the reactor build will create javadoc output files in each module's target directory. These can then be used by the aggregate goal to be combined.

This can be done by configuring your parent POM as follows:

<build>
    <plugins>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
            <!-- Default configuration for all reports -->
            <noqualifier>all</noqualifier>
            <destDir>javadoc</destDir>
        </configuration>
        <executions>
            <execution>
            <id>aggregate</id>
            <goals>
                <goal>aggregate</goal>
            </goals>
            <configuration>
                <!-- Specific configuration for the aggregate report -->
                <reportOutputDirectory>${user.dir}/documents</reportOutputDirectory>
                <destDir>javadoc</destDir>
            </configuration>
            </execution>
            ...
        </executions>
        </plugin>
        ...
    </plugins>
</build>

(there is no need for any additional configuration in the module POM files)

The aggregated javadoc can now be created by running

mvn compile javadoc:javadoc javadoc:aggregate

(note that the compile or package goal is required for reactor to resolve inter-module dependencies)

  • mvn javadoc:javadoc javadoc:aggregate I may have something else wrong with my project? I have 4 submodules. The reactor summary reports SUCCESS for the root project and first submodule (named shared), but fails on the second submodule (fhir) with "Could not resolve dependencies for project com.windofkeltia.pipeline:fhir:jar:4.0.0: Could not find artifact com.windofkeltia.pipeline:shared:jar:4.0.0 in central." I'm not ever trying to put the JARs coming out of my submodules into Maven Central. Note that I have no problem building normally (mvn package). – Russ Bateman Apr 20 '20 at 12:10
  • @RussBateman My bad, I forgot to add the compile or package goal. See updated answer. – Pieterjan Deconinck Apr 20 '20 at 15:45
  • No, that's not it. I still get the same thing. If you wanted to see the entire build: https://javahotchocolate.com/notes/maven-javadoc.html – Russ Bateman Apr 20 '20 at 17:14
  • Hmm, then you have something different in your project setup. Running with the ```install``` goal instead of ```compile``` should fix it for you, but it's not the cleanest solution. Example for reference: https://stackoverflow.com/questions/1677473 – Pieterjan Deconinck Apr 20 '20 at 17:25
  • 1
    Okay, yeah, this is awkward, but I'm now getting no errors and I find the aggregated Javadoc on the path _/target/site/apidocs/javadoc/index.html_. Use of `install` is acceptable. We do not ordinarily use the `install` goal--we build a NiFi NAR and placement/distribution is not done by Maven. (I followed that link, tried most every conclusive suggestion, but without ultimate happiness.) Thank you, Pieterjan! – Russ Bateman Apr 20 '20 at 20:31