• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | Maven Javadoc Plugin
  1. Maven Javadoc Plugin
  2. The help goal
  3. Example: Using javadoc plugin

  1. Maven Javadoc Plugin
    The Maven Javadoc Plugin uses the javadoc tool for generating API documentation for the specified project. It integrates seamlessly with Maven's build lifecycle and provides extensive customization options.

    Plugin coordinates:
    • Group Id: org.apache.maven.plugins
    • Artifact Id: maven-javadoc-plugin
    • Version: 3.11.2

    Plugin Prefix: javadoc

    The javadoc plugin provides the following goals:
    • help: Displays help information on maven-javadoc-plugin.

    • javadoc: Generates documentation for the main Java source code in a non-aggregator project using the standard Javadoc Tool.

    • jar: Bundles the Javadoc documentation for the main Java code in a non-aggregator project into a JAR file using the standard Javadoc Tool.

    • test-javadoc: Generates documentation for the test Java source code in a non-aggregator project using the standard Javadoc Tool.

    • test-jar: Bundles the Javadoc documentation for test Java code in a non-aggregator project into a JAR file using the standard Javadoc Tool.

    • javadoc-no-fork: Generates documentation for the Java code in a non-aggregator project using the standard Javadoc Tool without forking the build process. This goal requires source generation before site generation (e.g., by invoking mvn clean compile javadoc:javadoc-no-fork).

    • test-javadoc-no-fork: Generates documentation for the test Java code in a non-aggregator project using the standard Javadoc Tool without forking the build process. This goal requires test source generation before site generation.

    • aggregate: Generates documentation for the Java code in an aggregator (multi-module) project using the standard Javadoc Tool.

    • aggregate-jar: Bundles the Javadoc documentation for the main Java code in an aggregator project into a JAR file using the standard Javadoc Tool.

    • test-aggregate: Generates documentation for the test Java code in an aggregator project using the standard Javadoc Tool.

    • test-aggregate-jar: Bundles the Javadoc documentation for test Java code in an aggregator project into a JAR file using the standard Javadoc Tool.

    • aggregate-no-fork: Generates documentation for the Java code in an aggregator project using the standard Javadoc Tool without forking the build process.

    • test-aggregate-no-fork: Generates documentation for the test Java code in an aggregator project using the standard Javadoc Tool without forking the build process.

    • resource-bundle: Bundles the Javadoc directory along with Javadoc configuration options for distribution.

    • test-resource-bundle: Bundles the test Javadoc directory along with Javadoc configuration options for distribution.

    • fix: Automatically fixes Javadoc documentation and tags for the main Java source code in the project.

    • test-fix: Automatically fixes Javadoc documentation and tags for the test Java source code in the project.

    The Maven Javadoc Plugin supports numerous configuration options to customize the generated documentation:
    • source/target: Specify Java version compatibility.
    • show: Control visibility level (public, protected, package, private).
    • failOnError: Control build behavior on javadoc errors.
    • additionalJOptions: Pass additional options to the javadoc tool.

    Command line usage:
    # Generate javadoc in target/site/apidocs
    $ mvn javadoc:javadoc
    
    # Generate javadoc JAR file
    $ mvn javadoc:jar
    
    # Generate javadoc for multi-module project
    $ mvn javadoc:aggregate
  2. The help goal
    The help goal provides general information about the javadoc plugin, including available goals and their parameters.

    Use the detail parameter to get detailed information about all goals and their configuration options:
    # Display basic plugin information
    $ mvn javadoc:help
    
    # Display detailed information about all goals and parameters
    $ mvn javadoc:help -Ddetail=true
    If you need to use the plugin's full coordinates instead of its prefix, you can do that as follows:
    # Display basic plugin information
    $ mvn org.apache.maven.plugins:maven-javadoc-plugin:3.11.2:help
    
    # Display detailed information about all goals and parameters
    $ mvn org.apache.maven.plugins:maven-javadoc-plugin:3.11.2:help -Ddetail=true
    You can also use the Maven help plugin to describe the javadoc plugin:
    # Basic plugin description using help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-javadoc-plugin:3.11.2"
    
    # Detailed plugin description with all parameters
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-javadoc-plugin:3.11.2" -Ddetail=true
    To get specific information about a goal, use the goal parameter:
    # Help for the 'javadoc' goal
    $ mvn org.apache.maven.plugins:maven-javadoc-plugin:3.11.2:help -Dgoal=javadoc -Ddetail=true
    
    # Help for the 'javadoc' goal using the help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-javadoc-plugin:3.11.2" -Dgoal=javadoc -Ddetail=true
    Note: When using the plugin's help goal directly, you don't need to specify the version if the plugin is already configured in your POM or if you want to use the latest version.
  3. Example: Using javadoc plugin
    Here's a basic configuration example for your pom.xml file:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.11.2</version>
        <configuration>
            <source>23</source>
            <target>23</target>
            <show>private</show>
            <nohelp>true</nohelp>
            <failOnError>false</failOnError>
            <failOnWarnings>false</failOnWarnings>
            <additionalJOptions>
                <additionalJOption>-Xdoclint:none</additionalJOption>
            </additionalJOptions>
        </configuration>
        <executions>
            <execution>
                <id>generate-javadoc</id>
                <phase>package</phase>
                <goals>
                    <goal>jar</goal>
                    <goal>test-jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    Alternative approach using the site lifecycle:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.11.2</version>
        <executions>
            <execution>
                <id>attach-javadocs</id>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
© 2025  mtitek