• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | Site and Reports
  1. References
  2. Generating a site
  3. Deploying a site (FTP Server)
  4. Javadoc Reports
  5. Unit Test Reports
  6. Code Coverage Reports
  7. SpotBugs Report

  1. References
    See this page for more details about maven site:
    https://maven.apache.org/guides/mini/guide-site.html
    Maven Site Plugin Documentation

    See this page for more details on how to install and configure:
    vsftpd (FTP server)
    Apache HTTP Server
  2. Generating a site
    Update the pom.xml file and add the maven-site-plugin plugin with the latest stable version:
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>4.0.0-M13</version>
                <configuration>
                    <locales>en</locales>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.6.2</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>index</report>
                            <report>summary</report>
                            <report>dependencies</report>
                            <report>dependency-info</report>
                            <report>dependency-management</report>
                            <report>plugin-management</report>
                            <report>plugins</report>
                            <report>team</report>
                            <report>scm</report>
                            <report>issue-management</report>
                            <report>licenses</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
    To generate the site:
    $ mvn clean site
    By default, the resulting site will be in "target/site/" folder:
    $ ls -1 target/site/
    index.html
    project-info.html
    dependencies.html
    plugins.html
    css/
    images/
    ...
  3. Deploying a site (FTP Server)
    First let create the folder "maven-sites" where the site will be created:
    $ sudo mkdir /srv/ftp/maven-sites
    $ sudo chmod -R 775 /srv/ftp/maven-sites/
    $ sudo chown -R mtitek:ftp /srv/ftp/maven-sites/
    You should replace mtitek with your actual user name.

    Modify the "settings.xml" file to include the FTP server configuration:
    <servers>
        <server>
            <id>ftpServer</id>
            <username>admin1</username>
            <password>{encrypted_password}</password>
        </server>
    </servers>
    Modify the "pom.xml" file of your project to include the "site" configuration:
    <distributionManagement>
        <site>
            <id>ftpServer</id>
            <url>ftp://admin1@localhost/srv/ftp/maven-sites/mtitek-svn-test-a</url>
        </site>
    </distributionManagement>
    Modify the "pom.xml" file to include the "wagon-ftp" extension:
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ftp</artifactId>
                <version>3.5.3</version>
            </extension>
        </extensions>
    </build>
    Generating and deploying the Site:
    $ mvn clean site-deploy
    HTTP server: Creating a soft link to the site folder:
    $ sudo ln -s /srv/ftp/maven-sites /var/www/html/maven-sites
    You can use the browser to access the generated site: http://localhost/maven-sites/your-project-name/

    HTTP - Maven site
  4. Javadoc Reports
    To generate javadoc reports, you need to add Maven Javadoc Plugin to your pom.xml file:
    <reporting>
        <plugins>
            <!-- maven-project-info-reports-plugin -->
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.6.3</version>
                <configuration>
                    <doclint>none</doclint>
                    <failOnError>false</failOnError>
                    <quiet>true</quiet>
                    <source>${maven.compiler.source}</source>
                    <additionalJOptions>
                        <additionalJOption>-Xdoclint:none</additionalJOption>
                    </additionalJOptions>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>javadoc</report>
                            <report>test-javadoc</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
    To generate the reports:
    $ mvn clean site
    By default, the resulting javadoc will be in the folders "target/site/apidocs/" and "target/site/testapidocs/":
    $ ls -1 target/site/apidocs/
    index.html
    allclasses-index.html
    allpackages-index.html
    overview-tree.html
    ...
    $ ls -1 target/site/testapidocs/
    index.html
    allclasses-index.html
    allpackages-index.html
    ...
    Reports: JavaDoc - Unit Test - Code Quality:
    Reports: JavaDoc - Unit Test - Code Quality
  5. Unit Test Reports
    To generate unit test reports, you need to add Maven Surefire Report Plugin to your pom.xml file:
    <reporting>
        <plugins>
            <!-- maven-project-info-reports-plugin -->
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.2.5</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                            <report>failsafe-report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
    Note: This plugin also generates integration test reports if you're using the Failsafe plugin.

    To generate the reports:
    $ mvn clean test site
    By default, the resulting unit test reports will be in:
    - "target/site/surefire-report.html" (unit tests)
    - "target/site/failsafe-report.html" (integration tests)

    See screenshot above (Reports: JavaDoc - Unit Test - Code Quality).
  6. Code Coverage Reports
    JaCoCo is a code coverage tool that provides a measurement of how much source code was covered by unit tests.

    To generate code coverage reports, you need to add JaCoCo Plugin to your pom.xml file:
    <build>
        <plugins>
            <!-- maven-site-plugin -->
    
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <executions>
                    <execution>
                        <id>jacoco-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-prepare-agent-integration</id>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-integration-report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report-integration</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>INSTRUCTION</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.80</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <!-- maven-project-info-reports-plugin -->
    
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
    To generate the reports:
    $ mvn clean test site
    By default, the resulting code coverage reports will be in the folder "target/site/jacoco/":
    $ ls -1 target/site/jacoco/
    index.html
    jacoco.xml
    jacoco.csv
    jacoco-resources/
    ...
    Tip: You can set coverage thresholds to fail the build if coverage is too low, as shown in the configuration above (80% minimum).

    Reports: JaCoCo Code Coverage
  7. SpotBugs Report
    SpotBugs is a static code analysis tool that checks for bugs in the source code. It's the successor to FindBugs.

    To generate bug reports, you need to add SpotBugs Plugin to your pom.xml file:
    <reporting>
        <plugins>
            <!-- maven-project-info-reports-plugin -->
    
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.8.3.1</version>
                <configuration>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <xmlOutput>true</xmlOutput>
                    <spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs</spotbugsXmlOutputDirectory>
                    <excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
    Optional: Create a spotbugs-exclude.xml file in your project root to exclude certain bug patterns:
    <?xml version="1.0" encoding="UTF-8"?>
    <FindBugsFilter>
        <Match>
            <Bug pattern="DM_EXIT"/>
        </Match>
        <Match>
            <Class name="~.*\.Test.*"/>
        </Match>
    </FindBugsFilter>
    To generate the reports:
    $ mvn clean compile site
    By default, the resulting bug report will be in "target/site/spotbugs.html" file.

    See screenshot above (Reports: JavaDoc - Unit Test - Code Quality).
© 2025  mtitek