仅当特定配置文件在 Maven 中处于活动状态时才可以使用代理吗? [英] Is it possible to use proxy only when a specific profile is active in Maven?
问题描述
我只想在特定配置文件处于活动状态时使用代理.为了实现这一点,我的猜测是参数化
元素的
属性.但是,我不确定如何实现这一点.
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?
推荐答案
您可以尝试以下方法:
<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
,这样 proxy
的 active 到 false
.
So by default the proxy-off
profile would be active, which would set activate.proxy
to false
and as such active
of proxy
to false
.
然后执行:
mvn clean install -Pproxy-on
将激活 proxy-on
配置文件,并且对于 active
,整个链应为 true
.
Would activate the proxy-on
profile and the whole chain should result to true
for active
.
这篇关于仅当特定配置文件在 Maven 中处于活动状态时才可以使用代理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!