Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Maven profile enable/disable another profile from its definition?

Tags:

maven

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

like image 881
Robert Mugattarov Avatar asked Sep 14 '15 09:09

Robert Mugattarov


1 Answers

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.

like image 57
Tunaki Avatar answered Oct 16 '22 23:10

Tunaki