The Maven Release plugin can be used to release a project using Maven. Normally, a release can be made in two simple steps: prepare en perform. When the Mercurial SCM (Source Code Management) is used, this process requires a little more configuration. I performed the described steps using Hg (Mercurial) version 2.0.2 and maven-release-plugin version 2.4.2 on a Ubuntu 12.04 VM. The used distribution servers are Nexus 2.2-01 instances.
It’s important that all servers described in your pom.xml file, in my case a snapshot and a release server, are also configured in your Maven settings.xml file. Open your settings.xml file.
sudo gedit $MAVEN_HOME/settings.xml
The servers must be configured here. The ID should be identical to the ID used to describe the server in the pom.xml file. The username and password should represent a user which is allowed to create new distributions on the server.
<servers> <server> <id>snapshot_repository_id</id> <username>snapshot_repository_username</username> <password>snapshot_repository_password</password> </server> <server> <id>release_repository_id</id> <username>release_repository_username</username> <password>release_repository_password</password> </server> </servers>
The next step is the prepare statement. Normally, this statement can be executed by the following command. The –e flag is used to print the error stack trace in case the execution fails. Before you execute this statement, it’s important that all local modifications have been pushed to Mercurial.
mvn release:prepare –e
Where I executed this statement, the stack trace contained the following lines. For some reason, the authentication for the Mercurial isn’t set and you will not be prompted to enter a username and password.
[ERROR] EXECUTION FAILED Execution of cmd : push failed with exit code: 255. Working directory was: <My working directory> Your Hg installation seems to be valid and complete. Hg version: 2.0.2 (OK)
A workaround for this error that worked for me, was to split the actual prepare statement and the Mercurial push statements. To split these statements, a flag can be added to the prepare statement:
mvn release:prepare –e –DpushChanges=false
If this statement is executed successfully, you can manually push the changes to the Mercurial server using the following statement:
The final step of the Maven Release plugin is the perform step. Usually this can be done by executing the following statement. Again, the –e flag is toggled to display the stack traces of possible errors.
mvn release:perform –e
This statement also uses Hg operation, so probably this statement will fail too. However, it’s possible to set a username and password using flags. To do this, use the following statement.
mvn release:perform –e –Dusername=<SCM username> -Dpassword =<SCM password>
After this statement was executed successfully, the application was deployed and distributed successfully to the Nexus snapshot and Nexus release repositories.