我想仅在特定配置文件处于活动状态时才使用代理。为此,我的猜测是参数化<active>
元素的<proxy>
属性。但是,我不确定如何实现这一目标。
问题:如何仅在特定配置文件处于活动状态时才使用代理?
答案 0 :(得分:10)
您可以尝试以下方法:
<settings>
<proxies>
<proxy>
<id>httpproxy</id>
<active>${activate.proxy}</active>
<protocol>http</protocol>
<host>some.host</host>
<port>8080</port>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
<profiles>
<profile>
<id>proxy-on</id>
<properties>
<activate.proxy>true</activate.proxy>
</properties>
</profile>
<profile>
<id>proxy-off</id>
<properties>
<activate.proxy>false</activate.proxy>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>proxy-off</activeProfile>
</activeProfiles>
</settings>
因此,默认情况下,proxy-off
个人资料会处于有效状态,这会将activate.proxy
设置为false
,并active
proxy
设置为false
}。
然后执行:
mvn clean install -Pproxy-on
会激活proxy-on
个人资料,true
的{{1}}会产生整个链。
答案 1 :(得分:0)
这不回答原始问题,该问题询问有关配置文件的控制,但一种解决方法是忽略settings.xml
代理并在需要激活代理时设置MAVEN_OPTS
:
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"