Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 settings.xml to use both protocols. It seems to me that it is only possible to have one active proxy, as whichever active proxy is defined first is used, and subsequent 'active' proxy definitions are ignored. This is my settings.xml:

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

Is it possible to configure a proxy for both HTTP and HTTPS in maven's settings.xml? I'm aware that I could workaround this by passing Java system properties to the maven invocation such as:

-Dhttps.proxyHost=192.168.1.2 -Dhttps.proxyPort=3128 

but surely this must be possible from within settings.xml?

Maven bugs raised such as MNG-2305 and MNG-4394 suggest this issue is resolved, but I am not convinced.

Alternatively, is there a "proxy proxy" I could run locally that I could point maven to? The "proxy proxy" would route http/https accordingly. Even so, I would still need to define two active proxy definitions in settings.xml for Maven to direct both types of traffic.

like image 814
Stephen Hartley Avatar asked Jun 24 '15 16:06

Stephen Hartley


People also ask

What is HTTP proxy and HTTPS proxy?

HTTPS proxy can't cache anything as it doesn't see the request sent to the server. With HTTPS proxy you have a channel to the server and the client receives and validates server's certificate (and optionally vice versa). HTTP proxy, on the other hand, sees and has control over the request it received from the client.

What is nonProxyHosts in settings XML?

The nonProxyHosts setting accepts wild cards, and each host not to proxy is separated by the | character. This matches the JDK configuration equivalent. Please note that currently NTLM proxies are not supported as they have not been tested.


1 Answers

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.

like image 185
Krzysztof Krasoń Avatar answered Oct 02 '22 15:10

Krzysztof Krasoń