Maven catches a lot of flak from a lot of people. I’ve even been known to bemoan some its eccentricities from time to time. Over the past year and a half, though, I’ve done more and more with Maven, and I’m to the point now where that’s all I use. In fact, Maven and Ant have traded positions in my praise and scorn playbook. At any rate, in releasing FacesTester 0.1 yesterday, I was shown how to use the release plugin (which, by the way, has no parallel in Ant-space that I can see). This plugin helps in releasing a version of a project, updating all the version numbers as appropriate. Here’s a rough blow-by-blow of what happened:
I issued mvn release:prepare and mvn release:perform. The plugin asks me what the release version number should be, what the next version will be, and what the SCM tag should be. It has reasonable defaults for all of these, or you can specify something different. The plugin the did the following:
- Updated the version from 0.1-SNAPSHOT to 0.1 for the parent POM and each submodule
- Built each module
- Checked the POM changes into my SCM (Mercurial, btw)
- Tagged Mercurial to mark the release
- Deployed the artifacts to the configured Maven repository
- Updated the version number from 0.1 to 0.2-SNAPSHOT
- Checked the POM changes into Mercurial
Once that was done, I was able to update my development working copy, which got me to 0.2-SNAPSHOT and continue development. It was very, very slick. It’s a two-step process, and I can’t begin to explain the difference between prepare and perform in terms of what gets changed when and where. All I can tell is that it worked really well for me. :)
To make it work, though, you need to make sure your parent POM has these two entries:
<distributionManagement>
<repository>
<id>java.net-m2-repository</id>
<url>java-net:/maven2-repository/trunk/repository/</url>
<uniqueVersion>false</uniqueVersion>
</repository>
</distributionManagement>
<scm>
<connection>
scm:hg:https://kenai.com/hg/facestester~mercurial
</connection>
<developerConnection>
scm:hg:https://kenai.com/hg/facestester~mercurial
</developerConnection>
</scm>
Of course, your Maven repository and SCM URLs will be different. ;) I also needed to tell the SCM how to login to Mercurial. I did that by adding this to ~/.m2/settings.xml:
<servers>
<server>
<id>kenai.com</id>
<username>jasondlee</username>
<password>...</password>
</server>
</servers>
I didn’t actually try it without the password element there, which I will do next time I use the plugin. I’m not comfortable with putting my password in cleartext there, which is compounded by the fact that the plugin then echoes that password to the console as it runs. Other than that, I was really pleased with the process. Maven, when properly understood, is a much, much better tool than Ant. :)
Popularity: 20% [?]
Up 
A very cool feature of the release:prepare goal is that the release.properties file that is generated can be committed to SCM. This allows a given release to be completely and easily recreated at any time. Also, don’t forget about the dryRun property that prevents checkin or tagging to allow for a practice run so that the project is left untouched.
Also, with large projects, Maven’s batch mode option (mvn -B) can be very useful so that Maven won’t ask those questions for every module that is being deployed (think about deploying 20, 40 or more modules at once).
Hi, Bruce. Thanks for the tips. I have a LOT to learn still about Maven, but I’m committed. It’s a great tool that gets better the more you learn it. :)
glad you like it!
if you’re concerned about cleartext passwords, Maven 2.1.0 allows you to encrypt them (though that won’t help with the plugin that foolishly spits it out in the build process!)
Nice to see someone happy about maven stuff :-).
If you don’t want to store scm username/password use the following parameters in your cli : -Dusername= -Dpassword=
Brett and Olivier, Thanks for the tip. Someone on twitter actually pointed me in the direction of 2.1.0′s new feature minutes after I posted this. :) I think I have everything set up correctly for that now, so I’ll be able to test it when next I need to do a release, which should be soon. The CLI option isn’t real appealing as the password is then stored in my shell’s history file. :P
I have a problem with maven release with mercurial.
It works well if your pom.xml is at the root of your repo but I did not succeed to work if there are modules and want release modules seperately.
The problem comes from (I think) the hg clone does not manage subdirectories (as you can do on cvs or svn).
Someone has a solution?