Is it possible to use proxy only when a specific profile is active in Maven?

前端 未结 1 1636
栀梦
栀梦 2021-02-13 02:06

I would like to use proxy only when a specific profile is active. To accomplish this, my guess is to parameterize the property of

相关标签:
1条回答
  • 2021-02-13 02:53

    You could try the following approach:

    <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>
    

    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.

    Then executing with:

    mvn clean install -Pproxy-on
    

    Would activate the proxy-on profile and the whole chain should result to true for active.

    0 讨论(0)
提交回复
热议问题