I am writing my own Java 8 Stream implementation and want to inherit the Javadocs from the original java.util.stream.Stream
interface. However I cannot get it working. The generated Javadoc does only show my documentation but not the documentation from the extended Stream interface.
So for example, the javadoc of this method does only contain the text "Some additional information" but not the documentation from the Stream
interface.
/**
* {@inheritDoc}
* Some additional information.
*/
@Override
public Stream<T> filter(Predicate<? super T> predicate) {
// ... my stream implementation...
}
This is my configuration of the maven-javadoc-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<links>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
</links>
</configuration>
</plugin>
Do I miss something in this configuration? I set source
and target
to 1.8 in the maven-compiler-plugin. So according to the documentation of the maven-javadoc-plugin, the java API should be detected automatically.
There was also a similar question on Stack Overflow but the answers there do not seem helpful.
Tunaki's answer is great but as of Java 10 you have an even better option. If you pass
--override-methods=summary
to the Javadoc tool it'll push all inherited methods down to a "Methods declared in class X" section down below. This will list the inherited methods. Clicking on method names will take the user to the Javadoc definition in the base class.See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8187386 for background information.
That is expected,
javadoc
only copies comments from classes that are inside the source path. From Method Comment Inheritance:However, the sources of your JDK aren't in the source path, so
{@inheritDoc}
won't copy it. They need to be added explicitely; the Javadoc FAQ has this entry:So, to make it work:
maven-javadoc-plugin
to add those sources with thesourcepath
parameter.subpackages
to specify only our packages. Alternatively, we can useexcludePackageNames
to exclude the JDK packages.@apiNote
,@implSpec
and@implNote
. Those are custom tags that need to be added with thetags
parameter.Here's a sample configuration, where the path to the JDK sources is
/path/to/jdk/sources
(you could also use an environment variable, a property set by profile, etc.) and your own source files are all in the packagemy.package
:Generating the Javadoc, for example with
mvn javadoc:javadoc
, will correctly resolve the{@inheritDoc}
.