17

I would like to use proxy only when a specific profile is active. To accomplish this, my guess is to parameterize the <active> property of <proxy> element. However, I am not exactly sure how to accomplish this.

Question: How can I use proxy only when a specific profile is active?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Utku
  • 2,025
  • 22
  • 42
  • 1
    In the _settings.xml_ file, proxies are out of the profiles element, so this will not be possible (see here: https://maven.apache.org/settings.html#Proxies) – Tome Sep 06 '16 at 12:32
  • 2
    what might help: you can specify the settings.xml that maven uses with mvn -s /path/to/settings.xml - so having two configurations may possible for your case? – wemu Sep 06 '16 at 13:02

2 Answers2

1

This does not answer the original question, which asks about control-by-profile, but one workaround is to ignore settings.xml proxies and set MAVEN_OPTS when you need to activate a proxy:

export MAVEN_OPTS="-Dhttp.proxyHost=my-proxy-server -Dhttp.proxyPort=80 -Dhttp.nonProxyHosts=*.my.org -Dhttps.proxyHost=my-proxy-server -Dhttps.proxyPort=80 -Dhttps.nonProxyHosts=*.my.org"
javabrett
  • 7,020
  • 4
  • 51
  • 73
1

With

https://github.com/volkertb/autoproxy-maven-plugin/

or

https://github.com/c-a-services/overwrite-proxy-setting-plugin

you can set/clear the proxy during a later build phase.

(settings.xml <proxy> setting is not designed by maven to be dynamic with properties as property resolving happens after reading user settings.xml)