Search code examples
maven-2profileactivation

Activation of maven profile based on multiple properties


I am creating a maven 2 build for a project and I came up with profiles since the build has to be created for both different locations (say Berlin, Paris, North Pole) and different environment (Development, Production). Those are specified via properties. So for "North Pole" "DEV" I do:

-Dlocation=NorthPole -Denvironment=DEV

Now I would like to acivate my porfile based on both these properties, not just one. So I tried following:

<profiles>
  <profile>
    <id>NOrth Pole DEV</id>
    <activation>
      <property>
        <name>location</name>
        <value>NorthPole</value>
      </property>
      <property>
        <name>environment</name>
        <value>DEV</value>
      </property>
    </activation>
    ... <!-- Set some North Pole DEV specific stuff -->
  </profile>
</profiles>

This doesn't work, maven expect to see at most one <property> element there.

Please note I have another use for the properties as well so making it single property locationEnvof value NorthPole-DEV isn't what I want to have.

So is there any way or workaround or whatever else how to activate an profile based on combination of properties?


Solution

  • why not using profile directly like:

    <profiles>
       <profile>
        <id>north-pole</id>
        <activation>
          <activeByDefault>false</activeByDefault>
        </activation>
        ....
      </profile>
       <profile>
        <id>dev</id>
        <activation>
          <activeByDefault>false</activeByDefault>
        </activation>
        ....
      </profile>
    </profiles>
    

    Now you can activate the profiles by command line.

    mvn -Pdev,north-pole ...