views:

139

answers:

2

I'm looking for a way to create meta-profiles that just activate sub-profiles in Maven. Let's take a very concrete example. I have the following profiles:

  • "server-jboss"
  • "server-tomcat"
  • "database-hsql"
  • "database-oracle"

To build the project, you have to choose one profile for the server and one for the database. I want to create two "meta-profiles":

  • "dev" => "server-tomcat","database-hsql"
  • "prod" => "server-jboss","database-oracle"

The first idea that comes is to activate the subprofiles by a property:

<profile>
   <id>database-oracle</id>
   <activation>
     <property>
       <name>prod</name>
     </property>
   </activation>
</profile>

But this way, I cannot share subprofiles between meta-profiles. For example, I want my profile "database-oracle" to be activated by both "pre-prod" and "prod" meta-profiles.

Note: my sub-profiles just contain properties. They are used for filtering resources and in the child poms. This is why I think there could be a solution for this particular situation.

The ideal situation for me would be to have them externalized in external properties files, but one issue at a time ;)

+2  A: 

Activating profiles from another profile is not possible (this has been discussed in this previous question). Your first idea, using identical properties to activate different profiles, is the best thing you can implement but has indeed limitations.

Pascal Thivent
In this case, is there a trick to make a profile activated by several properties ? I see you can use ranges for the jdk version for example, may be there is some hidden syntax like <property><name>pord,pre-prod</name></property> ?
Julien Nicoulaud
+1  A: 

Have you tried a solution using the maven-properties-plugin? Some possibilities are discussed in this question and here.

Peter Lynch
Yes, I tried it, it looked like a good solution. Unfortunately, I could not make it work correctly: I loaded properties files in the POM, it worked well for resources filtering, but not for using them directly in the POM.
Julien Nicoulaud