Saturday, December 20, 2008

Mercurial (HG) Source Control with Maven

I've been using Mercurial for quite some time now. I've also been back up to my old tricks. On switching jobs a while back I came back into using Maven. I've also been hacking up some projects with pals and we host them on my site blueleftistconstructor. We found it would be easier to work on, distributed as we are, if we used Maven and created a Maven repository.

Well these projects are under Mercurial source control. I won't go to much into why I use Mercurial, especially why I use it over git, darcs and so forth. Lets just say I suits me and my partners.

So how easy is it to use Maven with Mercurial? Very easy it turns out. There was a little snag which I will get to later. First though you need to go get Mercurial. If you have a Mac you probably can just use easy_install, which is likely already installed. Try this:
easy_install mercurial
Using easy_install is my perferred method of installation. Otherwise download from the site.

Once you have verified Mercurial installed you just need to go into your projects root folder and type 'hg init' and you'll see Mercurial taking care of adding needed files. Now you will want to use the 'hg add' command to add files into source control. Read the docs for more information on how you can 'ignore' files.

Ok now we are ready to tell Maven that we are using HG to control. You will need to configure the scm section of your projects pom. It should look something like this:


<scm>
<connection>scm:hg:https://www.blueleftistconstructor.com/hg/netflix-client</connection>
<developerConnection>scm:hg:https://www.blueleftistconstructor.com/hg/netflix-client</developerConnection>
<url>https://www.blueleftistconstructor.com/hg/netflix-client</url>
</scm>


Note that you will have to replace the URLs above with your own. The 'connection' URL is a public accessible URL, while 'developerConnection' is not going to be read only. The 'url' is a source control browser such as ViewVC or Fisheye.

Thats it. You now can use all sorts of Maven commands to manage source control actions. I myself don't often use these. The real benefit here is in releasing versions of your software. With the source control repo configured Maven takes care of committing, tagging, and rolling the version number up.

For more on releasing a Maven project that is configured for source control read this, and this.