How to configure a proxy server for both HTTP and HTTPS in Maven's settings.xml?

后端 未结 4 1672
無奈伤痛
無奈伤痛 2020-12-30 19:04

I\'m using Maven 3.1.1 behind a proxy server. The same proxy handles both HTTP and HTTPS traffic.

I can\'t seem to tell maven using s

4条回答
  •  死守一世寂寞
    2020-12-30 19:47

    My tests with Eclipse Maven show that the protocol in settings.xml is referring to the protocol of the proxy server, not the protocol of the URL request. It also shows that Maven only uses the first active proxy server listed, and ignores the rest.

    Here's my evidence:

    1. The documentation says that

    active: true if this proxy is active. This is useful for declaring a set of proxies, but only one may be active at a time.

    protocol, host, port: The protocol://host:port of the proxy, separated into discrete elements."

    2. The source code is even clearer:

        /**
         * Get the protocol of the proxy server.
         * @return the protocol of the proxy server
         */
        public String getProtocol()
        {
            return protocol;
        }
    

    3. Real world tests (using Eclipse Maven):

    a. 1st proxy is a bogus ftp, 2nd is real http, 3rd is real https. Result: FAIL.

    If the protocol were for the URL request, then Maven would've looked up the real http/https proxies and worked perfectly fine. Instead, it used the 1st proxy even though it was "ftp", and failed.

        
            
                bogus_ftp
                true
                ftp
                123
                bogus.proxy.com
            
            
                real_http
                true
                http
                123
                real.proxy.com
            
            
                real_https
                true
                https
                123
                real.proxy.com
            
        
    

    b. 1st proxy is real http, 2nd is bogus https. Result: SUCCESS.

    This shows that it only used the 1st proxy. Otherwise, it would have used the 2nd proxy for https requests, hit the bogus proxy server, and failed.

        
            
                real_http
                true
                http
                123
                real.proxy.com
            
            
                bogus_https
                true
                https
                123
                bogus.proxy.com
            
        
    

    c. Both are http, but 1st proxy is bogus, 2nd is real. Result: FAIL.

    This shows that maven doesn't use multiple proxies, even for the same protocol. Otherwise, it would have tried the 2nd real proxy and succeeded.

        
            
                bogus_http
                true
                http
                123
                bogus.proxy.com
            
            
                real_http
                true
                http
                123
                real.proxy.com
            
        
    

提交回复
热议问题