Can access maven repository from behind proxy, nee

2020-02-08 06:22发布

问题:

I am trying to access maven repository from behind proxy. I configured settings.xml correctly (i guess so...)

  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <username>username</username>
      <password>password</password>  
      <host>12.34.56.78</host>
      <port>8080</port>
    </proxy>
  </proxies>

But still I am getting an error message like... if i don't configure userid/password gets correct error message which is HTTP response code 407 - saying authentication required. But If I configure correct/incorrect proxy authentication it always prints below error message....

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-clean-plugin:pom:2.2' from repository central (http://repo1.maven.org/maven2): Error trans
ferring file: Server redirected too many  times (20)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-clean-plugin:pom:2.2' from repository central (http://repo1.maven.org/maven2): Error trans
ferring file: Server redirected too many  times (20)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR

回答1:

Is it a NTLM proxy? If yes, try to supply domainname\username for the username (as suggested in this thread).

<username>DOMAINNAME\USERNAME</username>


回答2:

If above does not work

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 here.

  • 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.



回答3:

Another alternative is to get Cntlm (http://cntlm.sourceforge.net/) on your machine, configure your NTLM proxy in cntlm.ini with your domain/password/proxy name etc. run it :

cntlm.exe -v -a NTLMv2 -c cntlm.ini

Edit your maven $MAVEN_HOME\conf\settings.xml, and use proxies block:

<proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>localhost</host>
      <port>3128</port>
      <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
   </proxy>
</proxies>

Now run maven with -s option:

mvn -s $MAVEN_HOME\conf\settings.xml <goal>


回答4:

I too stumble upon this issue, spent a lot of time to search for a solution to NTLM error. NTLM issue does not get away even if we prefix user name with domain name just in proxy tag, we also need to prefix user ids in server tags like given below...

<server>
    <id>isb-libs-dev</id>
    <username><internal.java.corp>\username</username>
    <password>password</password>
</server>


标签: maven-2 proxy