How do I use Maven through a proxy?

For details of setting up a proxy for Maven, see the mini guide.

Essentially you need to ensure the proxies section in either the global settings ([maven install]/conf/settings.xml), or user settings (${user.home}/.m2/settings.xml) is configured correctly. It is better to do this in your user settings to avoid storing the password in plain text in a public location.

Maven 2.1 introduced password encryption, but I’ve not got round to checking if the encryption applies for the proxy settings as well as repository passwords (don’t see why it wouldn’t though).

For info, there is a commented-out proxy configuration in your settings.xml and instructions on how to modify it.

From the mini-guide, your settings should look something like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
[...]
  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
[...]
</settings>

Leave a Comment