zjffdu
zjffdu

Reputation: 28734

Unable to connect to maven repository when using proxy

My machine is using proxy to connect internet. But I get the following error when running maven build command. And it works when I disable proxy. I don't understand why proxy matters here.

    [ERROR] Failed to execute goal on project flink-dist_2.11: Could not resolve dependencies for project org.apache.flink:flink-
dist_2.11:jar:1.7-SNAPSHOT: Failed to collect dependencies at 

    org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
 Failed to read artifact descriptor for org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
 Could not transfer artifact 
    org.apache.flink:flink-shaded-hadoop2-uber:pom:1.7-SNAPSHOT from/to apache.snapshots (https://repository.
apache.org/snapshots): Remote host closed connection during handshake: SSL peer shut down incorrectly -> [Help 1]

Upvotes: 1

Views: 3454

Answers (5)

zappee
zappee

Reputation: 22646

I faced to the same problem at my work where we have Windows workstations and NTLM2 proxy server with authentication.

The following solution works fine for me. The benefit of this solution is that it can work with Maven, Git, IntelliJ IDE as well.

Reccomended steps you need to accomplish in order to have access via NTLM2 proxy:

  1. First you need to download, configure and run Cntlm proxy on your pc.
  2. Start Cntlm on your localhost. This proxy will forward all your local unauthenticated HTTP/HTTPS requests to the company proxy as a authenticated requests.
  3. Configure Maven, Git, IntelliJ, Eclipse, etc. to use your local proxy on localhost:3128. You do not need to configure authentication here.

Details:

  1. Download Cntlm proxy from here.
  2. Type cntlm.exe -H -d your_domain -u your_username. It will ask your password. Enter it and Cntlm will give you the hashes, something like this:

    Password:
    PassLM          4E9C185932FER43543RWEFER33R4R34C
    PassNT          6E9F1254353RDR34RFSDWER3443RDC9A
    PassNTLMv2      43534RFWDWE3434RWFWER434C4FA224F  
    
  3. Edit / check your cntlm.ini file

    Username   <your-domain-username>
    Domain     <windows-donain-name>
    Auth       NTLMv2
    PassNTLMv2 <hash>
    Proxy      <proxy-host:port>
    NoProxy    localhost, 127.0.0.*, 10.*, 192.168.*
    Listen     3128
    
  4. Start Cntlm with a simple script: start-proxy.cmd

    cd %CNTLM_HOME%
    
    rem verbose mode
    cntlm -v -c cntlm.ini
    
    rem verbose with logfile
    rem cntlm -v -c cntlm.ini -T %CNTLM_HOME%\nctlm.log
    
    rem test configuration
    rem cntlm -c cntlm.ini -I -M http://google.com
    
  5. Stop Cntlm server: stop-proxy.cmd

    taskkill /IM cntlm.exe /F
    

Then you can create two cmd files which change Maven configuration as per your flavour:

  1. mvn-internet.cmd

    call java8.cmd
    del %MAVEN_HOME%\conf\settings.xml
    copy %MAVEN_HOME%\conf\settings.xml.internet %MAVEN_HOME%\conf\settings.xml
    
  2. mvn-intranet.cmd

    call java8.cmd
    del %MAVEN_HOME%\conf\settings.xml
    copy %MAVEN_HOME%\conf\settings.xml.nexus %MAVEN_HOME%\conf\settings.xml
    
  3. settings.xml.internet

    <settings xmlns=...>
        <localRepository>...</localRepository>
        <proxies>
            <proxy>
                <id>my-proxy</id>
                <active>true</active>
                <protocol>http</protocol>
                <host>localhost</host>
                <port>3128</port>
                <nonProxyHosts>locahost</nonProxyHosts>
            </proxy>
        </proxies>
    </settings>
    
  4. settings.xml.nexus

    <settings>
        <localRepository>...</localRepository>
        <mirrors>
            <mirror>
                <id>local-lalm</id>
                <name>local-lalm</name>
                <url>https://nexus.xxx...</url>
                <mirrorOf>*</mirrorOf>
            </mirror>
        </mirrors>  
        <profiles>
            <profile>
                <id>use-local-repo</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <repositories>
                    <repository>
                        <id>LALM-global</id>
                        <url>https://nexus.xxx...</url>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>LALM-global</id>
                        <url>https://nexus.xxx...</url>
                    </pluginRepository>
                </pluginRepositories>
                <properties>
                    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                </properties>
            </profile>
        </profiles>
    </settings>
    

Do the same with Git

  1. git-internet.cmd

    call java8.cmd
    rem git config --global http.proxy username:password@localhost:3128
    git config --global http.proxy localhost:3128
    
  2. git-intranet.cmd

    call java8.cmd
    git config --global --unset http.proxy
    

Cunfigure IntelliJ

  1. Set up IntelliJ to use proxy on localhost:3128
  2. Set up Maven in IntelliJ: change Maven home directory and User settings file configs.

After that you will use the same Maven configuration within IntelliJ and command line so everythink will work on the same way from IDE and comand line.

You can use your new cmd files to change between use or not proxy server on the fly.

This configuration takes 10 mins. and after that you can forgot this proxy issue.

Upvotes: 0

A_C
A_C

Reputation: 925

May be try this by configuring Mavan accordingly for using the proxy server:- https://dzone.com/articles/how-get-maven-working-through

Upvotes: 0

Java.net
Java.net

Reputation: 187

Remote host closed connection during handshake: SSL peer shut down incorrectly : This indicates that the server host that your are trying to achieve is down, verify first if the connection is well established and try again.

Upvotes: 0

Arun K
Arun K

Reputation: 115

Have you tried the settings.xml at ${user.home}/.m2/settings.xml , more guidance here https://maven.apache.org/guides/mini/guide-proxies.html

in windows7 and above it would be c:\users\user_name\.m2

Upvotes: 1

Alexis Dufrenoy
Alexis Dufrenoy

Reputation: 11946

Maven is trying to connect to a remote repository in order to downlod your project dependencies in its local repository. That's a network connection and obviously, your proxy configuration makes Maven fail in the attempt.

Upvotes: 0

Related Questions