问题
I have two Maven profiles profile-A and profile-B. "B" should only be activated if "A" is not activated. So if I would call
mvn install
profile-B is executed (but not profile-A). But if I would call
mvn install -Pprofile-A
then only profile-A is executed (but not profile-B).
Any hints how I need to write my pom.xml to achieve this?
I already tried this, but it doesn't work:
<profiles>
<profile>
<id>profile-A</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
...
</profile>
<profile>
<id>profile-B</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!profile-A</name>
</property>
...
</activation>
...
</profile>
</profiles>
回答1:
I think for your example command line to work as expected, all you need is the <activeByDefault>true</activeByDefault>
for profile B.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html states:
All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
来源:https://stackoverflow.com/questions/7344728/maven-only-activate-profile-a-if-profile-b-is-not-activated