Sonatype Blog: Latest Posts

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:

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.

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.

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.