Last Updated on Tuesday, 26 March 2013 15:32
This Maven release plugin tutorial shows you how to tag your Maven project in Subversion and release the versioned “jar” to a remote repository (Nexus), and all of this with a single maven command! You can even automate the entire release process by running the command in a cronjob or a Continuous Integration system. Find below a cookbook on the plugin configuration and some maven release plugin tips and troubleshooting.
Define in line 4-6 the url of your source code management system.
if you have an anonymous user you can checkout your project using the scm plugin. To checkin and release you probably need to define the user and password of your scm repository in your settings.xml file as described below
Define in line 7 the id of the server. It should be equals to the host name of your scm url.
In line 8 and 9 the login and password to your scm repository
First what does mean SNAPSHOT ? SNAPSHOT is a special version in Maven that indicates the latest code; typically TRUNK or HEAD in your source control. With this version, Maven will automatically grab the latest SNAPSHOT every time you build. On the other hand, when you are using 2.0, once maven has downloaded this artifact, it never tries to get a new 2.0.
In this concept, a version just has a -SNAPSHOT suffix which marks the version as a SNAPSHOT (or non-release) version.
A SNAPSHOT version (e.g. 1.0-SNAPSHOT) would always be assumed more recent than the corresponding release version (e.g. 1.0)
Why should you use SNAPSHOT ? You should use SNAPSHOT for rapidly moving code where bug fixes and enhancements are coming fast.
Let's take the version 1.0-SNAPSHOT of our project :
- Make sure that your maven pom.xml does not include any SNAPSHOT dependencies.
- Make sure that all local changes are checked in in your source code management system.
- Make sure all unit tests pass
All of the above are required. The next step will gracefully fail with a warning if the above conditions are not met.
This step does everything needed in order to make a Maven release, including tagging the project, but does not actually make the release. It will check for local modifications, SNAPSHOT dependencies, calculate the release version, the next SNAPSHOT version.
In order to create the new tags you need the default subversion directory structure already in place :
You will be asked to specify the version for your release and also the next SNAPSHOT version that you want to assign to your project. Accept the default values if unsure.
In this example we will press two times <enter> key to keep the Maven proposed value
|SCM Release tag or label||mvcSample-1.0|
|New development version||1.1-SNAPSHOT|
If everything works fine you should see a new tag in your tags folder with the the release version you specified in point 3 above.
Maven will collect all the information that you provide and write a local file called "release.properties". This file lets you continue from where you left in case of errors.
You can undo everything you’ve done so far with mvn release:clean to start over
Once you’ve actually prepared the release using mvn release:prepare, you can make the release by typing the following command
You need to have the distribution management attribute defined in your pom. Let's define a nexus repository to release our project
Then we need to define the corresponding login and password according to the nexus repository
And the right connector defined
This command uses release.properties created by the previous step and does the following
- Checks out code tagged in the previous step. It figures out the tag version from the release.properties file.
- Runs maven deploy site-deploy goals to deploy the released version. This step is responsible for deploying the jar to the remote repository.
- Clean up. After the release is done, release.properties file will be deleted.
Congratulation you did your first release !
If you found this article useful please click on the following Google +1 button to promote this website.
Thanks in advance
If you use an SCM such as Subversion, the release plugin will tag the remote repository. That’s fine, but if you are using a distributed SCM such as Git or Mercurial, you will need to change the default behavior which:
- makes local commits to upgrade the versions,
- makes a local tag for the new version
- pushes all the changes upstream…
This behavior is awful, as it forces you into a model where you always have an upstream repository. Even if this is your case like most projets do, you are likely to have issues in Maven launching your “DVCS push” command. You will probably prefer to do it by yourself, which is an extra advantage if you run into an issue at the later stages of the release process, because you can always undo your commits locally.
Include the following snippet in the <build><plugins> section of your project's pom.xml-file to make the release plugin behave as one would expect with a DVCS::
Error Bootstraping - No Goal has been specified for this build...
Did you define a goal for scm plugin
Repository element was not specified in the POM inside distributionManagement element
Did you define the distribution management attribute in your project object model ?
No connector available to access repository nexus-release (scp://devhcrserv.s-h.ch/nexus/content/repositories/releases/)
Did you define a connector
e.g. : Webdav connector
Failed to transfer file when you deploy in a nexus repository (return code 503)
- You are probably trying to deploy in the wrong repository. e.g. Snashot instead of release
- You defined the wrong user/password to access the repository
- You have local modification not checked in
Failed to transfer file Return code is: 401
You have an http error 401 unauthorized
- You defined the wrong user/password to access the nexusrepository
- You don't define a user password to access the nexus repository
If you enjoyed this tutorial and want to promote it don't hesitate to click on
Maven related articles
If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on
Sébastien Dante Ursini
17 Years of experience in Java top online casino
22 Year in Banking/Finance
Based in Geneva/Switzerland