LinuxCommandLibrary

mvn-site

Generate project documentation site

TLDR

Generate a project site using the site plugin

$ mvn site
copy

Generate a site for a specific Maven project (multi-module build)
$ mvn site [[-pl|--projects]] [module_name]
copy

Clean previous site output before generating a new one
$ mvn clean site
copy

Skip tests while generating the site
$ mvn site [[-D|--define]] skipTests
copy

Generate and deploy the site to the remote server
$ mvn site-deploy
copy

SYNOPSIS

mvn [options] site[:goal]
mvn [options] site:stage
mvn [options] site:deploy

PARAMETERS

site
    The primary Maven goal to generate the project website in the target/site directory. This generates all reports and custom content as configured.

site:stage
    Generates the project site into a local staging directory (target/staging by default), typically used for reviewing the site's content and structure before its actual deployment.

site:deploy
    Generates the project site and then deploys it to the remote server configured in the project's <distributionManagement> section of the pom.xml file. This requires proper server credentials in settings.xml.

-D<property>=<value>
    Sets a system property that can influence the site generation or deployment. Common uses include -Dsite.url=http://example.com/ to override the site URL for deployment, or -Dmaven.site.skip=true to skip site generation during a build lifecycle phase.

-P <profile_id>
    Activates a specific Maven build profile defined in pom.xml or settings.xml. Profiles are often used to define different site configurations, such as alternative deployment targets, custom report sets, or specific environments.

-s <file>, --settings <file>
    Specifies an alternate path to the user's settings.xml file. This file is crucial for storing server credentials (passwords, private keys) used by the site:deploy goal for authentication with the remote deployment server.

-B, --batch-mode
    Runs Maven in non-interactive (batch) mode. This is highly recommended for automated builds in Continuous Integration/Continuous Delivery (CI/CD) pipelines to prevent the build process from halting due to prompts for user input.

-U, --update-snapshots
    Forces a check for updated releases and snapshots on remote repositories. This ensures that the latest versions of site plugins and project dependencies are used during the site generation process, which can be critical for security fixes or new features.

DESCRIPTION

The mvn site command (invoking the Maven Site Plugin) is used to generate a comprehensive project website, including documentation, reports, and general project information. This command compiles information from various Maven plugins (e.g., Javadoc, Surefire for test reports, Project Info) and custom content from the src/site directory. The generated site provides a centralized, browsable view of a project's status and details, which is invaluable for project stakeholders and developers alike. It relies heavily on the project's pom.xml configuration for specifying site-specific settings, reports, and deployment targets. The process typically involves generating the site locally for review (mvn site or mvn site:stage) and then deploying it to a remote server (mvn site:deploy) via configured protocols. This command is fundamental for maintaining up-to-date project documentation and transparent project status.

CAVEATS

Site generation can be resource-intensive and time-consuming, especially for large projects with numerous reports or complex configurations. Successful deployment via mvn site:deploy is contingent on correctly configured <distributionManagement> in pom.xml and appropriate server credentials in settings.xml. Care must be taken to avoid publishing sensitive project or build information on publicly accessible sites. Regular review of generated content and security updates for Maven plugins are advised.

SITE DESCRIPTOR (<I>SITE.XML</I>)

Located in src/site/site.xml, this XML file is used to customize the generated site's menu, navigation structure, look-and-feel (e.g., by linking custom CSS), and the content hierarchy. It allows projects to tailor the site to their specific needs beyond the default Maven structure.

DISTRIBUTION MANAGEMENT CONFIGURATION

The <distributionManagement> section within a project's pom.xml is essential for the mvn site:deploy goal. It specifies the remote URL where the site will be deployed (e.g., via SCP, FTP, or WebDAV) and defines a unique <id> that Maven uses to locate corresponding authentication credentials in the settings.xml file.

WAGON PLUGIN AND TRANSPORTS

Maven's Wagon API and its various implementations (e.g., wagon-ssh for SCP, wagon-ftp for FTP, wagon-webdav for WebDAV) provide the underlying transport layer for deploying artifacts and sites. The specific Wagon plugin used is determined by the protocol specified in the <distributionManagement> URL in the pom.xml.

HISTORY

The Apache Maven project, established in the early 2000s, revolutionized Java project builds with its 'convention over configuration' paradigm. From its early versions, a core feature was the ability to generate standardized project documentation and reports. The Maven Site Plugin has been a foundational component, providing a consistent mechanism for project teams to produce comprehensive, browsable websites that consolidate various project facets, significantly improving project transparency, communication, and overall maintainability.

SEE ALSO

mvn(1), git(1), scp(1)

Copied to clipboard