Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven javadoc plugin - how can I include only certain classes?

Tags:

Using the Maven javadoc plugin you can exclude certain packages - but I have lots of packages and only a handful of classes I want to produce Javadoc for.

Is there a way to include rather than exclude?

I would also like to do things on a class level rather than a package level as I have some classes in a package which need javadoc and some which don't.

like image 297
Supertux Avatar asked Jul 28 '09 17:07

Supertux


People also ask

What is Maven Javadoc skip?

skip Option. The Maven Javadoc plugin has provided a maven. javadoc. skip option to skip the Javadoc generation. Our Maven build won't generate Javadocs if we pass this option with the value true when we build our project: mvn clean install -Dmaven.javadoc.skip=true.

What is Maven Javadoc plugin used for?

The Javadoc Plugin uses the Javadoc tool to generate javadocs for the specified project. For more information about the standard Javadoc tool, please refer to Reference Guide. The Javadoc Plugin gets the parameter values that will be used from the plugin configuration specified in the pom.

Which command should you use to package Javadoc into a jar file?

The “maven-javadoc” plugin uses “ JDK\bin\javadoc.exe ” command to generate javadocs, pack in jar file and deploy along with your project.

Which will prevent Javadoc from being generated while using Doclint?

The magic incantation you need is -Xdoclint:none . This goes on the command line invoking Javadoc.


2 Answers

Since maven-javadoc-plugin version 2.9, you can do this in your configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>2.9</version>
  <configuration>
    ....
    <sourceFileIncludes>
      <include>Foo.java</include>
      <include>Bar.java</include>
    </sourceFileIncludes>
    <sourcepath>${basedir}/src/main/java/path/to/foo-and-bar</sourcepath>
    ....
  </configuration>
  ....

... which would build a Javadoc site only including the mentioned classes.

like image 179
RCross Avatar answered Oct 02 '22 05:10

RCross


Using the maven-javadoc-plugin, you cannot specify specific java classess (though you can with the javadoc utility, see below). However, via the the sourcepath configuration option for the javadoc:javadoc goal, you can configure specific packages. An example of this follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <charset>UTF-8</charset>
        <docencoding>UTF-8</docencoding>
        <docfilessubdirs>true</docfilessubdirs>
        <links>
            <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
        </links>
        <show>protected</show>
        <source>1.5</source>
        <sourcepath>${basedir}/src/main/java/com/acme/foo</sourcepath>
    </configuration>
    <reportSets>
        <reportSet>
            <reports>
                <report>javadoc</report>
            </reports>
        </reportSet>
    </reportSets>
</plugin>

In this example, all classes under the com.acme.foo package (including subpackages) will have javadoc generated.

It should be noted that this Maven plugin is simply a wrapper around Sun's javadoc utility. As such, most of the documentation and configuration for javadoc holds true for this plugin. See Sun's documentation on the javadoc sourcepath parameter.

In an area where the maven-javadoc-plugin differs in functionality, Sun's documentation for the sourcepath parameter mentions that it is possible with the javadoc utility to generate javadoc for specific classes. This capability is not available with the maven-javadoc-plugin. An example of this is shown in Sun's documentation:

  C:> cd C:\home\src\java\awt
  C:> javadoc -d C:\home\html Button.java Canvas.java Graphics*.java
like image 31
shek Avatar answered Oct 02 '22 05:10

shek