Skip to main content

Manage Maven Settings Templates in Nexus Repository 2

Nexus Repository 2

To manage Maven Settings templates, click on Maven Settings in the Enterprise section of the main menu on the left side of the user interface. This will load the panel shown in Figure 12.1, “The Maven Settings Panel”.

5410900.png

Figure 12.1. The Maven Settings Panel

The Maven Settings panel allows you to add, delete, and edit settings templates. The default template has an ID of default and can not be changed. It contains the recommended settings for a standard repository manager 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 repository manager 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 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 repository manager.

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 repository manager 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 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 Security Setup with User Tokens is enabled and configured.