Wednesday, April 29, 2009

Deploying Maven Artifacts to Googlecode

Recently I need to deploy a snapshot of one of my opensource projects, into a Maven repository so it could be used by another project. Having a quick look around it seemed that I needed to setup a Maven repository such as Archiva or deploy to a site such as java.net. Neither prospect appealed to me very much.

I had a look at Tom's instinct project and noticed that he was using googlecode to host his artifacts. Now that's more like it! I came across this article that Tom had written on how to export artifacts from Ant into subversion. I didn't fancy using Ant as I wanted to go a purely maven route.

Subsequently I came across this excellent blurb on how to deploy artifacts to a WebDAv server. The author goes on to say that "The trick to this one is to realize that when you share a Subversion repository over HTTP(S), it is actually implemented as a superset of WebDAV". Who knew? That basically means you can use your subversion repository on googlecode as a WebDAv repository.

Cool. I implemented his proposed solution and it all worked with minimal fussing around.

So here are the steps I used to get this working:

1. Update your project pom.xml with the following:


<distributionManagement>
<repository>
<id>your-reposiotory-id</id>
<name>your-reposiotory-name</name>
<url>dav:https://your-googlecode-project/svn/maven/repository</url>
</repository>
<snapshotRepository>
<id>your-snapshot-repository-id</id>
<url>dav:https://your-googlecode-project/svn/maven/repository-snapshot</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>

2. Update your settings.xml with the following:

<servers>
<server>
<id>your-repository-id</id>
<username>your-googlecode-username</username>
<password>your-googlecode-password</password>
<filePermissions>775</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
</servers>
</settings>


The repository id from the pom and the server id from the settings.xml link up a repository with it's server properties. The wagon extension in the pom is needed to do the actual upload.

Now to upload your artifact to your maven repository do a:


mvn clean install deploy:deploy


That's about it if it all goes well. If you get an 401 http error or the like check the file and directory permissions under the server tag in your settings.xml.

For a client to access your freshly created maven repository and artifacts, they need to add the following to an active profile in their settings.xml file:



<profiles>
<profile>
<id>active-profile-id</id>
<repositories>
<repository>
<id>snapshot-repository-id</id>
<url>http://your-googlecode-project/svn/maven/repository-snapshot</url>
</repository>
<repository>
<id>release-repository-id</id>
<url>http://your-googlecode-project/svn/maven/repository</url>
</repository>
</repositories>
</profile>
</profiles>


That should all work and now you can use your googlecode subversion as a maven repository! :)

1 comment:

Michael Bedward said...

Many thanks for this. It works like a charm !