Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 934
Jan Zyka Avatar asked Mar 24 '11 10:03

Jan Zyka


People also ask

How do I run a specific profile in Maven?

What you should do is check the profile behavior by doing the following : set activeByDefault to true in the profile configuration, run mvn help:active-profiles (to make sure it is effectively activated even without -Pdev1 ), run mvn install .


1 Answers

I am afraid there is no good solution to your problem (unless there are new Maven features I am not aware of).

In theory, you could introduce a derived property whose value is concatenated from the two properties you listed. However, the problem is that profiles are evaluated before properties defined in the pom, so such a derived property can't be used to activate a profile :-(

The best workaround I could think of for a similar problem was to activate the profile explicitly, and put the different combinations of command line parameters into separate batch/script files to make execution simpler and avoid mistyping issues.

like image 147
Péter Török Avatar answered Oct 11 '22 19:10

Péter Török