:
Skip Navigation
Resources Blog Nexus Tips and Tricks: Publishing Maven Sites to Nexus 1.4

Nexus Tips and Tricks: Publishing Maven Sites to Nexus 1.4

Nexus Professional provides a new hosted repository type: a Maven Site repository. This repository can be used to hold a Maven-generated web site. In addition to publishing your artifacts to a Nexus repository, you can also use Nexus to serve your project's web sites.

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. 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:

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

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. Site deployment to Nexus Professional requires version 2.0.1 or higher of the Maven Site Plugin.

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

Adding Credentials to Your Maven Settings

When the Maven Site plugin deploys a site to Nexus, it will need to supply the appropriate deployment credentials to Nexus. To configure this, you will need to add credentials to your Maven Settings. Open up your ~/.m2/settings.xml and add the following server configuration to the servers element. If you already have a servers element, just add a new server element with the appropriate id, username, and password. This example uses the default deployment user and the default deployment user password for Nexus.

<settings>
  <servers>
    <server>
      <id>nexus-site</id>
      <username>deployment</username>
<password>deployment123</password>
    </server>
  </servers>
 </settings>

Creating a Maven Site Repository

To create a Maven Site Repository, log in as a user with Administrative privileges, and click on "Repositories" under Views/Repositories in the Nexus menu. Under the Repositories tab, click on the Add... dropdown and choose "Hosted Repository" as shown in the following figure.

In the New Hosted Repository form, click on the Repository Type dropdown and chose the Maven Site Repository format as shown in the next figure. Although you can use any arbitrary name and identifier for your own Nexus repository, for the chapter's example, use a Repository ID of "site" and a Repository Name of "Maven Site".

After creating a new Maven Site repository, it should appear in the listed of Nexus repositories as shown in the next figure.

Add the Site Deployment Role

In the Maven Settings shown previously, you configured your Maven instance to use the default deployment user and password. To successfully deploy a site to Nexus, you will need to make sure that the deployment user has the appropriate role and permissions. To add the site deployment role to the deployment user, click on Users under the Security section of the Nexus menu, and then highlight the deployment user as shown in the next figure.

Locate the "Repo: All Maven Site Repositories (Full Control)" role in the Available Roles list, click this role, and drag it over to the Selected Roles list. Once the role is in the Selected Roles list, click on the Save button to update the roles for the deployment user. The deployment user will now have the ability to publish sites to a Maven Site repository.

Publishing a Site to Nexus

To publish a site to a Maven Site repository in Nexus Professional, run mvn site site:deploy from your project's base directory. The Maven Site plugin will deploy this site to Nexus using the credentials stored in your Maven Settings.

~/examples/sample-site$ mvn site site:deploy
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-site
[INFO]    task-segment: [site, site:deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [site:site {execution: default-site}]
[INFO] Generating "About" report.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project Team" report.
[INFO] Generating "Dependencies" report.
[INFO] Generating "Project Plugins" report.
[INFO] Generating "Continuous Integration" report.
[INFO] Generating "Source Repository" report.
[INFO] Generating "Project License" report.
[INFO] Generating "Mailing Lists" report.
[INFO] Generating "Plugin Management" report.
[INFO] Generating "Project Summary" report.
[INFO] [site:deploy {execution: default-cli}]
http://localhost:8081/nexus/content/sites/site/ - Session: Opened
Uploading: ./css/maven-base.css to http://localhost:8081/nexus/content/sites/site/
#http://localhost:8081/nexus/content/sites/site//./css/maven-base.css \
- Status code: 201
Transfer finished. 2297 bytes copied in 0.052 seconds
Uploading: ./css/maven-theme.css to http://localhost:8081/nexus/content/sites/site/
#http://localhost:8081/nexus/content/sites/site//./css/maven-theme.css \
- Status code: 201
Transfer finished. 2801 bytes copied in 0.017 seconds
Transfer finished. 5235 bytes copied in 0.012 seconds
http://localhost:8081/nexus/content/sites/site/ - Session: Disconnecting
http://localhost:8081/nexus/content/sites/site/ - Session: Disconnected
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45 seconds
[INFO] Finished at: Sat Oct 03 07:52:35 CDT 2009
[INFO] Final Memory: 35M/80M
[INFO] ------------------------

Once the site has been publish, you can load the site in a browser by going to http://localhost:8081/nexus/content/sites/site/.

Picture of Tim OBrien

Written by Tim OBrien

Tim is a Software Architect with experience in all aspects of software development from project inception to developing scaleable production architectures for large-scale systems during critical, high-risk events such as Black Friday. He has helped many organizations ranging from small startups to Fortune 100 companies take a more strategic approach to adopting and evaluating technology and managing the risks associated with change.