Ad

Can A Maven Profile Enable/disable Another Profile From Its Definition?

- 1 answer

Given two profiles A and B, is it possible to specify something within profile A definition that would enable or disable profile B?

Ad

Answer

This is not possible to activate / deactivate a profile from another profile. Maven needs to know the list of active profiles before building the model.

There are a couple of work-arounds depending on your use-case:

  • Set one profile to activeByDefault: it will be automatically deactivated when another profile is activated.
  • Use a custom property so that one profile is activated by the presence of the property and the other profile is deactivated by the presence of the property. Sample configuration would look like:

    <profile>
        <id>profileA</id>
        <activation>
            <property>
                <name>somename</name>
            </property>
        </activation>
    </profile>
    <profile>
        <id>profileB</id>
        <activation>
            <property>
                <name>!somename</name>
            </property>
        </activation>
    </profile> 
    

    Thus, if you invoke Maven with -Dsomename, profileA will be activated; otherwise profileB will be activated.

Ad
source: stackoverflow.com
Ad