Apache Maven Site Plugin

1. Overview

The Site Plugin is used to generate a site for the project. The generated site also includes the project's reports that were configured in the POM.

2. Plugin Goals

The Site Plugin has seven goals:
  • site:site is used generate a site for a single project. Note that links between module sites in a multi module build will not work, since local build directory structure doesn't match deployed site.
  • site:deploy is used to deploy the generated site using Wagon supported protocol to the site URL specified in the section of the POM.
  • site:run starts the site up, rendering documents as requested for faster editing. It uses Jetty as the web server.
  • site:stage generates a site in a local staging or mock directory based on the site URL specified in the section of the POM. It can be used to test that links between module sites in a multi module build work. This goal requires the site to already have been generated using the site goal, such as by calling mvn site.
  • site:stage-deploy deploys the generated site to a staging or mock directory to the site URL specified in the section of the POM.
  • site:attach-descriptor adds the site descriptor (site.xml) to the list of files to be installed/deployed. For more references of the site descriptor, here's a link.
  • site:jar bundles the site output into a JAR so that it can be deployed to a repository.
  • site:effective-site calculates the effective site descriptor, after inheritance and interpolation.
  1. Usage You can generate different kind of reports.
  • Generating a Site
  • Deploying a Site
  • Staging a Site
  • Running a Site

Generating a Site

To generate the project's site and reports, execute:
mvn site
By default, the resulting site will be in the target/site/ directory.

Deploying a Site

To be able to deploy the site, you must first specify where the site will be deployed. This is set in the element of the POM as shown below.
<project>
  ...
  <distributionManagement>
    <site>
      <id>www.yourcompany.com</id>
      <url>scp://www.yourcompany.com/www/docs/project/</url>
    </site>
  </distributionManagement>
  ...
</project>
The element identifies the repository, so that you can attach credentials to it in your settings.xml file using the element as you would for any other repository.
The gives the location to deploy to. In the example above we copy to the host www.mycompany.com using the path /www/docs/project/ over the scp protocol. You can read more about which protocols are supported on this page. If subprojects inherit the site URL from a parent POM, they will automatically append their to form their effective deployment location.
mvn site:deploy
If you want to generate the site and deploy it in one go, you can utilize the site-deploy phase of the site lifecycle. To do this, just execute:
mvn site-deploy

Staging a Site

To review/test the generated web site before an official deploy, you can stage the site in a specific directory. It will use the element or the project hierarchy to link the project and its modules.
Just execute the site:stage goal from your project
mvn site:stage

Running a Site

The Site Plugin can also be used to start up the site in Jetty. To do this, execute:
mvn site:run

4. Examples

In Maven, you can use “mvn site” to generate a documentation site for your project information.
mvn site
The generated site is under your project “target/site” folder.

5. Conclusion

In this quick guide, we went over the site plugin and gave instructions on using and customizing it. Also we have seen the different plugin goals and their usage.
Reference : https://maven.apache.org/plugins/maven-site-plugin/

Comments