Maven: Only activate profile A if profile B is not activated?

左心房为你撑大大i 提交于 2019-12-23 07:04:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!