Available in Nexus Repository OSS and Nexus Repository Pro
Nexus Repository Manager Pro and Nexus Repository Manager OSS include a repository provider for hosting static websites - the Site format. Hosted repositories with this format can be used to hold a Maven-generated website. This chapter details the process of configuring a site repository and configuring a simple Maven project to publish a Maven-generated project site to the repository manager.
Creating a New Maven Project
In this chapter, you will be creating a simple Maven project with a simple website that will be published to a Site repository. To create a new Maven project, use the archetype plugin’s
archetype:generate goal on the command line, and supply the following identifiers:
After running the
archetype:generate command, you will have a new project in a
Configuring Maven for Site Deployment
To deploy a site to a 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 the repository manager.
Add the following section to sample-site/pom.xml before the dependencies element. This section will tell Maven where to publish the Maven-generated project website:
Distribution Management for Site Deployment.
The URL in the distribution management does not change with the project versions automatically, which means that any redeployment overwrites old content and potentially leaves old stale files behind. To have a new deployment directory for each version, change the URL to a parameterized setup or a hardcoded specific URL for your project version.
If you combine this approach with a redirector or a static page that links to the different copies of your site, you can e.g., maintain separate sites hosting your javadoc and other documentation for different releases of your software.
The DAV protocol used by for deployment to the repository manager requires that you add the implementing library as a dependency to the Maven site plugin configuration.
Configuring Version 3.4 of the Maven Site Plugin with DAV support
Adding Credentials to Your Maven Settings
When the Maven Site plugin deploys a site to a repository, it needs to supply the appropriate deployment credentials. To configure this, you need to add credentials to your Maven Settings. Open up your
~/.m2/settings.xml and add the following server configuration to the servers element:
Configuring Deployment Credentials for Site Deployment
Configuring Deployment Credentials for Site Deployment uses the default deployment user and the default deployment user password. You will need to configure the username and password to match the values expected by your repository manager.
Creating a Site Repository
To create a site repository, log in as a user with Administrative privileges, and click on Repositories under Views/Repositories in the main menu. Under the Repositories tab, click on the Add… drop-down and choose Hosted Repository as shown in Figure 19.1, “Adding a Hosted Repository”.
Figure 19.1. Adding a Hosted Repository
In the New Hosted Repository form, click on the Provider drop-down and chose the Site provider as shown in Figure 19.2, “Creating a New Maven Site Repository” . Although you can use any arbitrary name and identifier for your own repository, for the chapter’s example, use a Repository ID of
site and a Repository Name of
Figure 19.2. Creating a New Maven Site Repository
After creating a new Site repository, it should appear in the list of repositories as shown in Figure 19.3, “Newly Created Site Repository” . Note that the Repository Path shown in Figure 19.3, “Newly Created Site Repository” is the same as the repository path referenced in Distribution Management for Site Deployment.
Figure 19.3. Newly Created Site Repository
The Site provider support is implemented in the Nexus Site Repository Plugin and is installed by default in Nexus Repository Manager OSS as well as Nexus Repository Manager Pro.
Add the Site Deployment Role
In the Maven Settings shown in Configuring Deployment Credentials for Site Deployment, you configured your Maven instance to use the default deployment user and password. To successfully deploy a site to the repository manager, 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 main menu, and click on the Add button in the Role Management section. This will trigger the display of the Add Roles dialog that will allow you to apply a filter value of site to locate the applicable roles as shown in Figure 19.4, “Adding the Site Deployment Role to the Deployment User”.
Figure 19.4. Adding the Site Deployment Role to the Deployment User
Check the box beside the Repo: All Site Repositories (Full Control) role in the list and press OK in the dialog. After the dialog closes, you should see the new role in the Role Management section. Click on the Save button to update the roles for the deployment user. The deployment user now has the ability to publish sites to a Maven site repository.
Publishing a Maven Site
To publish a site to a Site repository, run
mvn site-deploy from the
sample-site/ project created earlier in this chapter. The Maven Site plugin will deploy this site to the repository manager using the credentials stored in your Maven Settings.
Once the site has been published, you can load the site in a browser by going to http://localhost:8081/nexus/content/sites/site/.
Figure 19.5. Sample Site Maven Project Website