Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 342
Peter Meier Avatar asked Sep 08 '11 07:09

Peter Meier


People also ask

How do Maven profiles work?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.

How do I make Maven my default profile?

By using the attribute activeByDefault you will be able to select a default profile in Maven when no other profile is selected with the -P parameter.


1 Answers

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.

like image 126
ddso Avatar answered Oct 15 '22 18:10

ddso