I'm using Maven Javadoc Plugin like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
I have multiple JDK versions installed and want to be able to build a project with any of them. The above configuration works fine with Java 8, but it fails with Java 11 with the following error
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.1.1:jar (attach-javadocs) on project ...: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.
The obvious solution is to set JAVA_HOME. But as I mentioned, I have multiple versions of JDK, so reconfiguring JAVA_HOME every time I want to use another version wouldn't be convenient at all.
Another solution (from Unable to find javadoc command - maven) is to add the following configuration to the plugin:
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
This makes it work with Java 11, but breaks Java 8 because the javadoc
location is ${java.home}/../bin/javadoc
in that case.
Ideally I always want to use javadoc
from the directory where the java executable that Maven uses is, but I haven't found a way to do it with Maven Javadoc Plugin.