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

后端 未结 4 1646
無奈伤痛
無奈伤痛 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:42

    I solved the problem with updating the maven version, or in other words not using the embedded eclipse maven version, but external version 3.3.9.

    0 讨论(0)
  • 2020-12-30 19:43

    It works without the extra ...<id>httpsproxy</id>... entry (as @Krzysztof Krasoń mentioned) and with it (as the asker stated). The problem for us was, that the Eclipse->Maven->User Settings->[x] Update Settings was obviously not working at all and to test certain things Eclipse->Maven->[x] Download repository index updates on startup must be checked (e.g. Maven Repositories View->Global Repositories->central->Update Index). And most of all:

    Eclipse must be restarted after every settings.xml update! :-/

    I guess it's a bug or reload/caching issue. We successfully tested it with

    • Kepler (4.3) and Neon (4.6)
    • and their embedded Maven versions (3.2.1 / 3.3.9) as well as an external 3.3.3
    • with http:// and https:// URLs
    0 讨论(0)
  • 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.

        <proxies>
            <proxy>
                <id>bogus_ftp</id>
                <active>true</active>
                <protocol>ftp</protocol>
                <port>123</port>
                <host>bogus.proxy.com</host>
            </proxy>
            <proxy>
                <id>real_http</id>
                <active>true</active>
                <protocol>http</protocol>
                <port>123</port>
                <host>real.proxy.com</host>
            </proxy>
            <proxy>
                <id>real_https</id>
                <active>true</active>
                <protocol>https</protocol>
                <port>123</port>
                <host>real.proxy.com</host>
            </proxy>
        </proxies>
    

    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.

        <proxies>
            <proxy>
                <id>real_http</id>
                <active>true</active>
                <protocol>http</protocol>
                <port>123</port>
                <host>real.proxy.com</host>
            </proxy>
            <proxy>
                <id>bogus_https</id>
                <active>true</active>
                <protocol>https</protocol>
                <port>123</port>
                <host>bogus.proxy.com</host>
            </proxy>
        </proxies>
    

    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.

        <proxies>
            <proxy>
                <id>bogus_http</id>
                <active>true</active>
                <protocol>http</protocol>
                <port>123</port>
                <host>bogus.proxy.com</host>
            </proxy>
            <proxy>
                <id>real_http</id>
                <active>true</active>
                <protocol>http</protocol>
                <port>123</port>
                <host>real.proxy.com</host>
            </proxy>
        </proxies>
    
    0 讨论(0)
  • 2020-12-30 19:58

    Maven proxy from settings.xml is used for both http and https, so you just need to define one proxy server and it will be used for both, you just need to leave only one proxy tag, like this:

    <proxies>
        <proxy>
            <id>myhttpproxy</id>
            <active>true</active>
            <protocol>http</protocol>
            <host>192.168.1.2</host>
            <port>3128</port>
            <nonProxyHosts>localhost</nonProxyHosts>
        </proxy>
    </proxies>
    

    The protocol above is the protocol of the proxy server, not the proxied request.

    0 讨论(0)
提交回复
热议问题