I recently installed Maven at a client site that had a NTLM proxy, and ran into issues because it was failing to download maven dependencies. I was following the instructions provided by Maven to correctly setup my proxy settings, without any luck!
I kept getting the following error when attempting to run mvn install
goal to set up the project:
C:Dev\MavenTest> mvn clean install
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifa
escriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-pl
:pom:2.4.1 from/to central (http://repo.maven.apache.org/maven2): Not authorized by proxy, ReasonPhrase:Proxy Authentication Required (
ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ). -> [Help 1]
...
After few hours of Googling and trial and error, I finally found two methods of getting Maven to work with NTLM proxies.
Step #1: Add proxy settings to your Maven configuration file
- Open the Maven configuration file at
%M2_HOME%/conf/settings.xml
. For Linux, this is typically found at
${user.home}/.m2/settings.xml)
For Windows, this can be found in one of the following locations:
# In Win XP, Vista C:\Documents and Settings\username\.m2\settings.xml # In Windows 7/8 C:\users\username\.m2\settings.xml
- Find the section within
settings.xml
file that defines theproxies
node. This should look something like:<proxies> <!-- proxy | Specification for one proxy, to be used in connecting to the network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> ... </proxy> --> </proxies>
- Comment out the proxy node and enter your proxy information. Afterwords, the proxies node should look similar to:
<proxies> <proxy> <!-- id field is optional --> <id>something-descriptive-to-identify-your-proxy</id> <!-- Tells Maven to use this proxy. Specify 'false' if you want to turn it off. --> <active>true</active> <protocol>http</protocol> <!-- ENTER YOUR PROXY HOST NAME --> <host>company.proxy.host.com</host> <!-- ENTER YOUR PROXY HOST'S PORT NUMBER --> <port>8080</port> <!-- ENTER YOUR USER NAME TO LOGIN TO THE HOST --> <username>myUserName</username> <!-- ENTER YOUR PASSWORD ASSOCIATED WITH THE USERNAME --> <password>myPassword</password> <!-- Any URLs that you want to filter out (e.g. local repository?). Otherwise just keep this as it is --> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies>
IMPORTANT: Ensure that you change the host, port, username and password fields to match your environment/proxy setup.If the above settings doesn’t work, then you might want to change the username field to include the domain that the user belongs to. e.g.
<username>myDomain\myUserName</username>
Step #2: Add wagon-http-lightweight extension
Wagon HTTP lightweight library allows us to overcome authentication limitations in Maven (3.0.4) when working with NTLM proxies. We can follow the steps below to add the Wagon HTTP lightweight library as a Maven extension:
- Download the
wagon-http-lightweight-2.2.jar
from http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-http-lightweight/2.2/wagon-http-lightweight-2.2.jar - Copy the
wagon-http-lightweight-2.2.jar
to%M2_HOME%/lib/ext
folder.
Example POM.xml to test the solution
To test our approach, first create a simple Maven project with the following pom.xml:
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.thira.testmavenplugindl</groupId>
<artifactId>test-maven-plugin-dl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Test Maven Plugin Download Issue</name>
<description>Example pom file to test Maven dependency download with NTLM proxies</description>
</project>
The run the Maven goal described below. This should execute successfully and download all Maven dependencies:
mvn clean install
Check your local repository directory (as defined in settings.xml
file) to ensure all the dependencies are correctly downloaded.