Project Documentation in Maven

  

To generate project documentation in Maven, the standard way is to use the Maven Site Plugin. This plugin helps generate a complete site (including Javadoc, dependency info, reports, etc.) for your project.


Step-by-Step Guide

1. Add Site Plugin (optional for customization)

Maven includes the Site plugin by default, but you can customize it in pom.xml:


<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-site-plugin</artifactId>
      <version>4.0.0-M14</version> <!-- Latest version as of mid-2024 -->
    </plugin>
  </plugins>
</build>



2. Add Reporting Section (for documentation reports)

This section includes things like javadocsurefire-report, etc.


<reporting>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-project-info-reports-plugin</artifactId>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-report-plugin</artifactId>
    </plugin>
  </plugins>
</reporting>


3. Generate the Site

Use the following Maven command:

mvn site



This will:

  • Compile the code

  • Generate reports (Javadoc, tests, etc.)

  • Create an HTML site under the target/site directory



4. View the Site

Open the following file in a browser:

target/site/index.html





Common Reports Generated:


Report NameDescription
Project SummaryOverview of the project
JavaDocAPI documentation from source code comments
Surefire ReportTest results
Dependency InfoDependencies and dependency tree
SCM & Issue TrackingInfo from pom.xml