13.3. Configuring Maven for Site Deployment

To deploy a site to a Nexus Professional Maven Site repository, you will need to configure the project's distribution management settings, add site deployment information, and then update your Maven settings to include the appropriate credentials for Nexus.

~/examples$ cd sample-site
~/examples/sample-site$ more pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.sonatype.books.nexus</groupId>
  <artifactId>sample-site</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>sample-site</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Add the following section to sample-site/pom.xml after the dependencies element. This section will tell Maven where to publish the Maven-generated project web site:

Example 13.1. Distribution Management for Site Deployment to Nexus

  <distributionManagement>
    <site>
      <id>nexus-site</id>
      <url>dav:http://localhost:8081/nexus/content/sites/site/</url>
    </site>
  </distributionManagement>

Note

In Example 13.1, “Distribution Management for Site Deployment to Nexus”, there is a Nexus Professional installation running on localhost port 8081. In your environment you will need to customize this URL to point to your own Nexus instance.

In addition to the distributionManagement element, you will want to add the following build element that will configure Maven to use version 2.0.1 of the Maven Site plugin.

Example 13.2. Configuring the Maven Site Plugin for Nexus Site Deployment

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>2.0.1</version>
      </plugin>
    </plugins>
  </build>

Note

Site deployment to Nexus Professional requires version 2.0.1 or higher of the Maven Site Plugin.