Repository Management with Nexus

13.2. Manage Maven Settings Templates

To manage Maven settings templates, click on Maven Settings in the Enterprise section of the Nexus menu on the left side of the Nexus UI. This will load the panel shown in Figure 13.1, “The Maven Settings Panel”.

figs/web/maven-settings-template.png

Figure 13.1. The Maven Settings Panel


The Maven Settings panel allows you to add, delete, and edit Maven Settings templates. The default template has an ID of default and can not be changed. It contains the recommended settings for a standard Nexus installation. To create a new Maven settings template, click on the Add… button and select Settings Template. Once the new template is created, assign a name to the template in the Template ID text input and click the Save button.

To edit a template, click on a template that has a User Managed value of true in the list and edit the template in the tab below the list. Once you are finished editing the template, click Save to save the template. When editing the template you can insert some property references that will be replaced on the server with their values at request time:

baseurl
The base URL of the Nexus installation.
userId
The user id of the user that is generating a Maven Settings file from this template.

Server side interpolation takes effect even when the download of the settings template is done with tools like curl. These properties can be referenced in the settings file using the the syntax ${property}:

<settings>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>${baseurl}/content/groups/public</url>
    </mirror>
...

To preview a Maven settings template, click on the Template URL in the list. Clicking on this URL loads a dialog window that contains the Maven Settings file generated from this template. This rendered view of the Maven Settings template has all variable references replaced using the current context of the user. This is the result of running the property replacement on the Nexus server.

The Nexus M2Settings Maven Plugin supports the more powerful and feature-rich, client-side replacement of properties using a $[property] syntax.

Client-side properties supported by the Nexus M2Settings Maven Plugin are

baseurl
The base URL of the Nexus installation.
userId or username
The username of the user that is requesting a Maven Settings file from this template.
password
The password of the user.
userToken
The formatted user token composed of name code, : and pass code.
userToken.nameCode
The name code part of the user token.
userToken.passCode
The pass code part of the user token.
userToken.passCode.encrypted
The encrypted pass code part of the user token.

Client side interpolation allows you to fully populate a <server> section with the required properties either with the plain text username and password:

<server>
  <id>nexus</id>
  <username>$[username]</username>
  <password>$[password]</password>
</server>

You can also use the the usertoken equivalent:

<server>
  <id>nexus</id>
  <!-- User-token: $[userToken] -->
  <username>$[userToken.nameCode]</username>
  <password>$[userToken.passCode]</password>
</server>

Alternatively you can use Maven master-password encryption with the master keyword in settings-security.xml:

<server>
  <id>nexus-client-side-interp-encrypted</id>
  <!-- Maven master password encrypted user token password -->
  <username>$[userToken.nameCode]</username>
  <password>$[userToken.passCode.encrypted]</password>
</server>

The usage of the .encrypted key results in values similar to the following snippet:

<server>
  <id>nexus-client-side-interp-encrypted</id>
  <!-- master password encrypted user token password -->
  <username>KOYC8Q76</username>
  <password>{fsx2f...}</password>
</server>
[Warning]

userToken.* properties are only expanded to values if the User Token feature as documented in Section 6.17, “Security Setup with User Tokens” is enabled and configured.