25 February 2010

Auto-Install Maven into Hudson

It turns out to be easy to have Hudson download a version of Maven for you to use in your builds.I Googled for instructions and found none but then any Google for anything about Hudson is likely to find the river, the explorer or Jennifer.

I'm using Hudson 1.336 as I write.

You may need to figure out how to set up a proxy if your Hudson server is inside your companies network boundaries. The following instructions assume you have already got that working. I find the whole proxy issue confusing as there is a way documented to enter a proxy when deploying to a repository and a way to enter a proxy that is sort of hidden when updating plugins. I haven't seen one related to downloading tools.

1) Click on the "Manage Hudson" link on the top page.
2) Click on the "Configure System" link at the top of the list in the main part of the page.
3) Scroll Down to the "Maven" section and click the "add Maven button" as in the red circle below
4) Select "Add Installer"
5) The drop down list of install from options has an option "tar.gz" you should select.
6) "Label" field is blank. I don't know quite what this does.
7) Enter a link to one of the apache mirrors like: "http://mirror.uoregon.edu/apache/maven/binaries/apache-maven-2.2.1-bin.tar.gz" but you can pick your own mirror by opening another browser tab and going to "http://maven.apache.org/download.html" and clicking on the link for the tar.gz file in the "mirrors" column. I picked the one at the top of the top section on that page but you may want a not-latest version. That takes you to the page where it allows picking a mirror. Copy one of the mirror links for the site close to you. The link above is the one I picked.
8) The subdirectory will be like "apache-maven-2.2.1" with the main folder name from the tar.gz file you pointed to. Note that older versions of Maven (for example 2.0.7) are like "maven-2.0.7" and newer ones add the word "apache" to the front. This subdirectory is added to the root folder of where-ever Hudson puts tools that it downloads to produce the MAVEN_HOME value Hudson passes to Maven for builds using this Maven version.
9) Save the configuration changes with the button at the very bottom of the page (or just hit 'enter').

At this point in the process, I was left wondering when it would get downloaded and installed.

10) Create or edit an M2 build to use the new Maven version you just added. When it first runs, the tool will be added to a "tools/maven" folder inside your hudson folder structure AND THEN the build will kick off. (This might work with some other type of build but I haven't tried it.)