Repository Management with Nexus
12.3. Downloading Maven Settings with the Nexus Maven Plugin

12.3. Downloading Maven Settings with the Nexus Maven Plugin

Once you have defined a set of Maven templates, you can use the Nexus Maven plugin to distribute changes to the Maven Settings file to the entire organization.

12.3.1. Running the Nexus Maven Plugin

To invoke goals in the Nexus Maven plugin, you will initially have to use a fully qualified groupId and artifactId as shown in Invoking the Nexus Maven Plugin goal settings-download with a fully qualified groupId and artifactId.

Invoking the Nexus Maven Plugin goal settings-download with a fully qualified groupId and artifactId. 

mvn org.sonatype.plugins:nexus-maven-plugin:settings-download

To be able to invoke the plugin with the simple identifier "nexus" as shown in Invoking the Nexus Maven Plugin goal settings-download with a short identifier, you have to add the appropriate plugin group to your Maven Settings file as shown in Adding org.sonatype.plugins to pluginGroups in Maven Settings. An initial invocation of the settings-download goal will update your settings file, with a template from Nexus Professional. Every default template in Nexus Professional adds the org.sonatype.plugins group to the pluginGroups, so you will not have to do this manually. It is essential that you make sure that any new, custom templates also include this plugin group definition. Otherwise, there is a chance that a developer could update his or her Maven Settings and lose the ability to use the Nexus Maven plugin with the short identifier.

Invoking the Nexus Maven Plugin goal settings-download with a short identifier. 

mvn nexus:settings-download

Adding org.sonatype.plugins to pluginGroups in Maven Settings. 

<settings>
  ...
  <pluginGroups>
    <pluginGroup>org.sonatype.plugins</pluginGroup>
  </pluginGroups>
  ...
</settings>

The "settings-download" goal of the Nexus Maven Plugin downloads a Maven Settings file from Nexus Professional and stores it on a local machine. This goal can be configured to update a user’s ~/.m2/settings.xml file or the global configuration file which is stored in the Maven installation directory. If you are replacing a Maven Settings file, this goal can be configured to make a backup of an existing Maven Settings file.

12.3.2. Configuring Nexus Maven Plugin for Settings Management

The Settings Management goal in the Nexus Maven plugin requires security credentials and a base URL for the Nexus server you are interacting with. You can specify security credentials by supplying a username and password or by supplying a server id that corresponds to a server in your Maven Settings (~/.m2/settings.xml). The common configuration parameters and security configuration properties are:

nexusURL
Points to the Nexus server installation’s base URL. If you have installed Nexus on your local machine, this would be http://localhost:8081/nexus/
username
Username to use for authenticating to Nexus. Default value is $user.name.
password
Password to use for authenticating to Nexus
serverAuthId
You should specify either username and password or the serverAuthId. If you specify a value for serverAuthId, the Nexus Maven plugin is going to look at the contents of your ~/.m2/settings.xml file and use the username and password from a server definition.

In most cases a valid user login will be required to access your settings templates. By default, if you don’t specify the nexusURL and password parameters, the plugin will prompt you for them. If you don’t specify the username parameter, the Java System property $user.name will be used.

In addition to these security options, all of the Maven Settings management goals have the following configuration parameters:

verboseDebug
If verboseDebug is set to true Maven will print out debug messages that detail the plugin’s interaction with Nexus.
backupFormat
When backing up an existing settings.xml file, use this date format in conjunction with SimpleDateFormat to construct a new filename of the form: settings.xml.$(format). Date stamps are used for backup copies of the settings.xml to avoid overwriting previously backed up settings files. This protects against the case where the download mojo is used multiple times with incorrect settings, where using a single static backup-file name would destroy the original, pre-existing settings. Default value is: yyyyMMdd_HHmmss.
destination
The standard destination where the downloaded settings.xml template should be saved. If the destination is "global", the Nexus Maven plugin will save the Maven Settings file to $M2_HOME/conf. Is the destination is "user", the Nexus Maven plugin will save the Maven Settings file to ~/.m2/settings.xml. If the target parameter is set, it will override this value. Default value is: user.
doBackup
If true and there is a pre-existing settings.xml file in the way of this download, backup the file to a date-stamped filename, where the specific format of the date-stamp is given by the backupFormat parameter. Default value is: true.
encoding
Use this parameter to define a non-default encoding for the settings file.
target
If set, ignore the standard location given by the destination parameter, and use this file location to save the settings template instead. If this file exists, it will be backed up using the same logic as the standard locations (using the doBackup and backupFormat parameters).
url
The full URL of a settings template available from a particular Nexus Professional instance. If missing, the mojo will prompt for this value.

12.3.3. Downloading Maven Settings

To download Maven Settings from Nexus Professional, you will need to know the URL of the Maven Settings template. If you omit this URL on the command-line, the Nexus Maven plugin will prompt you for a URL when it is executed:

$ mvn org.sonatype.plugins:nexus-maven-plugin:settings-download
[INFO] [nexus:settings-download]
Settings Template URL: \
.../nexus/service/local/templates/settings/default/content
[INFO] Existing settings backed up to: \
/Users/tobrien/.m2/settings.xml.20090408_204422
[INFO] Settings saved to: /Users/tobrien/.m2/settings.xml

Alternatively, you can specify the username, password, and URL on the command line.

$ export NX_URL="http://localhost:8081/nexus/"
$ mvn org.sonatype.plugins:nexus-maven-plugin:settings-download \
-Durl=${NX_URL}/service/local/templates/settings/default/content \
-Dusername=admin \
-Dpassword=admin123</screen>
Sonatype Promotion Subscribe via RSS