Reputation: 965
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.
Upvotes: 45
Views: 50125
Reputation: 4765
For Eclipse 4.17 (2020-09) with M2E 1.16.1 (and the focus it should especially work there!) and Maven 3.3.3 (external) or 3.6.3 (embedded) (and likely similar combinations/versions) it works for mixed http://...
and https://...
repo URLs with the following setup (other than in the past):
e.g. to make it work for settings.xml
or pom.xml
:
<url> https://repo.maven.apache.org/maven2 </url>
<url> http://my-local-repo/repository/rep1 </url>
<url> http://my-local-sonatype-nexus-repo-manager-oss-v3/repository/rep2 </url>
you need:
two entries in your <usr-home>/.m2/settings.xml
if some repos have http://
and some https://
URLs (unfortunately not like maybe stated in docs or in older Maven or m2e versions/combinations)
<proxy>
<id>http</id>
<active>true</active>
<protocol>http</protocol>
<port>8080</port>
<host>some-proxy.com</host>
</proxy>
<proxy>
<id>https</id> <!-- important!: different id than above! -->
<active>true</active>
<protocol>https</protocol>
<port>8080</port>
<host>some-proxy.com</host>
</proxy>
additionally the Eclipse M2E plugin has the problem to not sync at all if the
Window -> Preferences -> Maven -> [x] Download repository index updates on startup is not enabled
(=> thus one could think of it as: "[x] Enable repository index updates (additionally on startup)")
furthermore some repos, e.g. the known Sonatype's Nexus Repository Manager v3 (at least 3.2), do not support indexing out-of-the-box (do not get confused by feature request NEXUS-17279) and thus one has at least two options:
Repo Admin UI -> Config -> Tasks -> Create Task ->
Maven - Publish Maven Indexer files
...)
Minimum Index Enabled
should suffice (may take 20 min to index for central)<repo-base-url>/repX/.index/nexus-maven-repository-index.properties
exists
to be sure to not run into caching or crash problems you should restart Eclipse (e.g. with -clean
option) in case something does not work right away after the above setup
Do not get confused: we experienced that the servers UI search (Nexus Manager) did not always display all available matches (but the M2E client did), e.g. "groovy-all"
did only return some 2.*
versions whereas some 3.*
were in fact also available.
Of course without indexing one would loose the ability to search within repo artifacts but the direct download should always work nevertheless.
pom.xml
-> right click -> Maven -> Add Dependency -> Enter groupId, artifactId ...
groovy
in this generic search field there should be quite some suggestions if it works, "artifactId cannot be empty" or "groupId cannot be empty" warnings can be ignored (and any content in both will be ignored then):
Full Index Enabled
must be checked (may take a while to complete)Upvotes: 2
Reputation: 4765
Update 2022-01: a more up-to-date answer/solution for the current tech-stack (Eclipse 4.17 / 2020-09) can be found here (old: 4.6 / 2017)
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 was obviously not working at all and to test certain things Eclipse->Maven->User Settings->[x] Update Settings
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
http://
and https://
URLsUpvotes: 3
Reputation: 38083
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>
Upvotes: 2
Reputation: 21
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.
Upvotes: 2
Reputation: 27516
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.
Upvotes: 58