« Fixing the roof | Main | Vindication »

Maven and Cargo through a proxy

If I had a dollar for every hour I've wasted trying to force yet another command line app to go through a HTTP proxy, I'd probably be $100 richer. The latest target for frustration was Cargo, as used by Maven. Here's four hours of hair-pulling pain, solved in 50 lines. Hope it saves someone else some hair.

Maven's proxy configuration is actually documented, so only takes a moderate amount of pain to realise you need to add the following to your ~/.m2/settings.xml file, before the final </settings> tag:

<proxies>
    <proxy>
        <active>true</active>
        <protocol>http</protocol>
        <host>proxy.server.com.au</host>
        <port>8080</port>
        <username>your_username</username>
        <password>your_password</password>
        <nonProxyHosts>*.server.com.au|whatever.com</nonProxyHosts>
    </proxy>
</proxies>

Maven is then able to connect to its various HTTP servers.

When Maven calls on the Cargo plugin however, there's some indication that Cargo is supposed to pick up Maven's proxy settings. I'm using Cygwin (it's the best I can do to hide the tragedy that is Windows, and it's not always pretty) and this didn't work.

In my pom.xml file for the project I was working on, there is a section that begins:

<plugins>
    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>

At some point, Maven calls on Cargo to download and install Tomcat. No amount of elaborate configuration could convince Cargo to use global proxy settings and the documentation is a long way from useful, so instead I had to make the settings specific to the Tomcat container. This is how you do that:

<plugins>
    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <configuration>
            <container>
                <containerId>tomcat5x</containerId>
                <zipUrlInstaller>
                    <proxy>
                        <host>proxy.server.com.au</host>
                        <port>8080</port>
                        <user>your_username</user>
                        <password>your_password</password>
                    </proxy>
                </zipUrlInstaller>
            </container>
        </configuration>
    </plugin>
</plugins>

And ta-da, Cargo is able to download Tomcat. Rinse, lather, repeat.

TrackBack

TrackBack URL for this entry:
http://heath.hrsoftworks.net/cgi-bin/mt-tracker.cgi/215

Post a comment