This post describes how to make a maven repo for your google code project. I’m a big fan of google code. It’s a tremendous service for those looking for a place to host their open source code. The only thing I lacked was a maven repo. I have to be honest here, while I use maven, it’s still a big mystery to me how things end up in the main maven repo. If Google were to add one new feature, I’d prefer it be a maven repo and hudson build that autodiscovers maven projects and builds them…but we’re not there yet, so the question I’m going to answer is how you can provide a maven repo for your open source customers hosted on google code. The secret is SVN and it’s HTTP support. If you can duplicate the directory stucture of a maven repositoty in your SVN, maven will be perfectly happy to seek dependencies from your project trunk.
Step 1: Install in your local repo
You’ve run mvn install on your project and have a jar file under the target folder. The first step is to install that file locally using the mvn install:install-file command.
mvn install:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar \
-DcreateChecksum=true
Note: the checksum part is important, maven will need that. “your.groupId” is typically a reverse domain, like we use in java package names.
Step 2:
Copy the results to a folder in your SVN tree and commit. Typically, the local repo will be in C:/Documets and Settings/yourid/.m2/repository. On unix it’s most likely under .m2 in your home. From there cd into the directory tree that matches the groupid you provided in step one, following it all the way down you’ll find a directory named after your artifactId containing all the necessary files for maven, including the jar. All you need to do is copy this tree into SVN and commit it back to your google code project.
Step 3
We’ve created a non-standard repo which maven won’t know about. Therefore, it’s necessary to make your build aware of it by including a reference to the repo (actually this can be done in your maven settings too). Here’s an example:
<repositories>
<repository>
<id>Jenabean</id>
<url>http://jenabean.googlecode.com/svn/trunk/repo</url>
</repository>
</repositories>
To summarize, you basically run mvn install locally, and copy the results to a place in your SVN project, and make maven aware of the base http svn path as a new repo. For further reading, Ian Dickenson has also provided a detailed look at using eclipse with Jena.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=223aa043-7ae3-4857-b675-69cfc2655592)
Have you looked into using wagon-svn [1] for SVN deployment?
If you start using that, please consider commenting-on/voting-for issue 4 [2] so that mime-types can get applied when deploying Maven sites.
Regards,
Luke
[1] https://wagon-svn.dev.java.net/
[2] https://wagon-svn.dev.java.net/issues/show_bug.cgi?id=4
Updated accordingly. But, the pom gets downloaded, the JAR is searched only @ the default repo and not @ the specified google code URL.
May I express my concern about this approach? This basically introduces microrepository. Users of these projects require either duplicate entries in their pom: one for the dependency and one for the repository, or put great burden on the maintainer of the local repository to add each microrepository by hand.
Often companies choose to maintain a locale repository in order not to be dependant on the internet and remote sites for their build process. These local repositories have the ability to automatically fetch used artifacts from remote repositories, but these repositories must be configured first. All these microrepositories do not make things easier.
So please instead of this solution have your Maven build post artifacts to a real repository like Java’s, Maven’s or Sontatype’s.
Please do NOT use this approach.
Sonatype provide free hosting of a Maven Repo for open source projects and BONUS! you get syncing to Maven Central too for free!!!
-Stephen
P.S.
In the interests of full disclosure, I do not work for Sonatype but some open source projects I run use the free hosting of maven repositories provided by Sonatype
thanks for the note, I didn’t know we could do that. I’ve been using wagon-svn lately. Perhaps a link on how to configure a simple build to post to Sonatype, when others happen by?
Great! Thanks for the info Stephen. I didn’t know you could do that. Somehow I though I needed my own public repo to sync with these central repos…plus…in the interests of full disclosure, I wasn’t able to find a clear, concise tutorial on how to do this.
I like using wagon-svn. And I like to have everything under one roof (the code and the maven artefacts), so I can easily control them.
Wagon-svn is as easy to use as just issuing following command:
mvn deploy:deploy-file -f pom.xml -DpomFile=pom.xml -Dfile=target/cool-project-lib-1.0.jar -Durl=svn:https://coolproject.googlecode.com/svn/repo
Best,
Nikola