One of the important pieces of the pie you will need when using Maven2 in your organization is Maven Proxy. Let me explain what this magnificent piece of software is. It is a partially documented masterpiece that will implements a shared repository for all team members and collaborators using maven. Lets face it. If you have about five or six developers each using Maven then you have the bandwidth required to load a local repository times five or six. Instead you can setup Maven proxy in an existing web container like Tomcat or Jetty or launch it from the command line and it will act like the Ibiblio repository. It downloads artifacts on the fly as needed from the official Ibilio Maven2 repository and caches them on disk for all team members to share. The biggest problem, for me at least, was setting it up. The first time I tried failed because we sit behind an authenticating HTTP proxy and I wasn’t exactly clear on how to get Maven Proxy to talk through it. Well after chatting on the #Maven #IRC channel I really got discouraged. Apparently nobody there at the time had experience with setting up Maven Proxy over the Ibilio M2 repository. I almost threw in the towel on Maven2 altogether until I hit the Maven mailing list with my problems. After a few exchanged emails with one particularly helpful person I was all set up and running Maven Proxy for my team here. I haven’t had any problems since (though there is this existing issue with retrieving the assembly plugin but I attribute that to the codehaus outage issue). So my purpose today is to introduce you to what I feel is a common problem with configuring Maven proxy.
Maven Proxy and HTTP proxy authentication
The most important thing you need to download after downloading Maven Proxy is the config file. (I’m not sure why it’s not included in the bundle for Maven-proxy but go figure.) You’ll want the 0.2 version. Towards the bottom of this file you will see a section outlining a list of proxies. It looks like you can actually configure a separate proxy for each repo though you’ll most likely need to configure only one for all repos as I did. There is a proxy.list property with a comment that I just figured out two seconds ago. (Honestly I couldn’t understand what it meant by auto discovering the proxies but now I see that it is the authors intention to not need the proxy.list property.) Each entry in the comma delimited list should point to a group of properties beggining proxy.<entry-name> defining the attributes for that proxy. Now here’s the tricky part that got me and at least one other fellow. For each repository defined below the list of proxies there is an optional property pointing to which proxy it should use. See my partial config listing here as an example:
#This is just a hack, it should auto discover them
#This is not just a hack, it specifies the order repositories should be checked
#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/"
# The local store represents a location that local jars you host can be located.
# This could also be achieved by having a local http repository, but this is less cumbersome
repo.local-repo.description=Neware In-office Maven Repository
#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos
#If hardfail is true, any unexpected errors from the repository will cause
#the client download to fail (typically with a 500 error)
#Don't cache a file repository
#Cache this repository for 1 hour
These are the most important properties to set in this file along with the first property listed at the top. (The first property defines where the cache is stored.) You’ll see in my above example how I define a proxy named instagate (that’s the internet appliance we use as our HTTP proxy/gateway) and then reference the proxy by name in the definitions for each repository.
I hope that clears things for at least one other person struggling to get Maven-proxy working. I just realized something. I typically try to be funny during my post to keep readers interested yet the above text has not even a speck of humor. Purple monkey! Purple monkey! Purple monkey! Wasn’t that funny? Not to me either. I must be losing my touch. Maybe next time I’ll joke more. Until later, holla at me…