You can do everything that was described in Section 9.7, “Managing Staging Repositories in Nexus” with the Nexus Maven Plugin. Using the Nexus Maven Plugin you can:
-
Close a Staging Repository
-
Promote a Staging Repository
-
Drop a Staging Repository
-
List All Available Staging Repositories
To invoke goals in the Nexus Maven plugin, you will want
to add the appropriate plugin group to your Maven settings file. Add the
org.sonatype.plugins groupId to ~/.m2/settings.xml as shown in Example 9.3, “Adding org.sonatype.plugins to pluginGroups in Maven
Settings”.
Example 9.3. Adding org.sonatype.plugins to pluginGroups in Maven Settings
<settings>
...
<pluginGroups>
<pluginGroup>org.sonatype.plugins</pluginGroup>
</pluginGroups>
...
</settings>Adding the org.sonatype.plugins group
to your Maven Settings will allow you to run the following goals from
the Nexus Maven Plugin:
- nexus:staging-finish
-
This goal will close a staging repository from Maven. This goal in the Nexus Maven plugin corresponds to the procedure described in Section 9.7.1, “Closing an Open Repository”.
- nexus:staging-list
-
This goal will list all of the staging repositories which are currently visible to a user.
- nexus:staging-drop
-
This goal allows you to drop a specific staging repository. If no repositories are specified for this goal, this plugin will present an interactive menu listing all of the closed staging repositories currently eligible for a drop operation.
- nexus:staging-promote
-
This goal allows you to promote a specific repository. If no repositories are specified for this goal, this plugin will present an interactive menu listing all of the closed staging repositories currently eligible for a promote operation.
Once you have configured the pluginGroup in
your Maven Settings file, you can run the Nexus Maven plugin from the
command line. In order to access the staging suite in your Nexus
instance, the plugin must be told where Nexus is.
$ mvn nexus:staging-list
All of the Staging goals in the Nexus Maven plugin require security credentials and a base URL for the Nexus server you are attempting to manage. 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.xmlfile and use the username and password from a server definition.
In most cases a valid user login will be required to access your
staging information. 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 staging goals have a common configuration property which controls the logging level.
- verboseDebug
-
If verboseDebug is set to true Maven will print out debug messages that detail the plugin's interaction with Nexus.
Once you've deployed one or more sets of artifacts as release candidate to Nexus, you'll have one or more open staging repositories. There are a variety of actions you can take with these repositories, but maybe one of the most basic is to list them. This gives you a pretty good view into the status of your release(s). The basic command is:
$ mvn nexus:staging-list
[...]
[INFO] Logging into Nexus: http://localhost:8082/nexus
[INFO] User: testuser
[INFO]
[INFO] The following OPEN staging repositories were found:
- staging-003 (profile: Example Profile)
URL: http://localhost:8082/nexus/content/repositories/staging-003
[INFO] The following CLOSED staging repositories were found:
- staging-001 (profile: Example Profile)
URL: http://localhost:8082/nexus/content/repositories/staging-001
Description: This is a test repository
- staging-002 (profile: Example Profile)
URL: http://localhost:8082/nexus/content/repositories/staging-002
Description: This is another test repositoryYou can find more information about this Mojo here.
Before your team can run any tests against the set of artifacts that constitute your release, you need to mark the open staging repository as closed. This means that no additional artifacts can be added to that specific staging repository, making the set of artifacts it contains an immutable snapshot. When it is closed, the repository will become available for artifact resolution. The basic command is:
$ mvn nexus:staging-close [INFO] Available Staging Repositories: 1: staging-002 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-002 Select a repository to close (1) 1: : 1 Repository Description: This is a test repository [INFO] Finishing staging repository for: 'com.myco:my-project:1': - staging-002 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-002 [INFO] The following CLOSED staging repositories were found for: \ 'com.myco:my-project:1': - staging-001 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-001 Description: This is a test repository - staging-002 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-002 Description: This is another test repository
The output above shows that the staging-close Mojo found an open staging repository - staging-001 - for the current project, then told Nexus to close it. Afterward, it displayed the list of closed staging repositories, which included the one we just closed. If you don't have an open staging repository, you'll see something like this instead:
No open staging repositories found. Nothing to do! [INFO] The following CLOSED staging repositories were found for: \ 'com.myco:my-project:1': - staging-001 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-001 Description: This is a test repository - staging-002 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-002 Description: This is another test repository
You can find more information about this Mojo here.
In the unfortunate event that your project artifacts fail during testing, you may need to drop the staging repository that houses them, in order to avoid confusing them with newer candidate releases. The basic command is:
$ mvn nexus:staging-drop [INFO] Available Staging Repositories: 1: staging-006 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-006 Description: This is a test repository Select a repository to drop (1) 1: : 1 [INFO] Dropping staged repository: - staging-006 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-006 Description: This is a test repository
The Mojo will present you with a list of closed staging repositories, with the first in the list selected as the default response. If you simply hit the Enter key, the default will be used; otherwise, the repository corresponding to the number you select will be used. If you have no closed staging repositories, you'll see something like this instead:
[INFO] No closed staging repositories found. Nothing to do!
You can find more information about this Mojo here.
On the other hand, if your project artifacts pass all tests, you will find that you need to promote the staging repository that houses them, in order to finalize the release and make the artifacts available for public consumption. The basic command is:
$ mvn nexus:staging-promote [INFO] Available Staging Repositories: 1: staging-006 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-006 Description: This is a test repository Select a repository to promote (1) 1: : 1 Target Repository ID: releases [INFO] Promoting staging repository to: releases: - staging-006 (profile: Example Profile) URL: http://localhost:8082/nexus/content/repositories/staging-006 Description: This is a test repository
The Mojo will present you with a list of closed staging repositories, with the first in the list selected as the default response. If you simply hit the Enter key, the default will be used; otherwise, the repository corresponding to the number you select will be used. If you have no closed staging repositories, you'll see something like this instead:
[INFO] No closed staging repositories found. Nothing to do!
You can find more information about this Mojo here.
