4

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 ;)

kazanaki
  • 7,988
  • 8
  • 52
  • 79
nicoulaj
  • 3,463
  • 4
  • 27
  • 32
  • Actually, this question really sounds like a dupe of http://stackoverflow.com/questions/2246033/why-cant-i-activate-a-maven2-profile-from-another-profile. Please confirm if you think it's a different question. – Pascal Thivent Feb 19 '10 at 14:58
  • Yes, I browsed those questions, but I think there could be some trick in my situation. My sub-profiles are just sets of properties that I want to aggregate. May be the title of my question is a little bit ambitious ;) – nicoulaj Feb 19 '10 at 15:04

2 Answers2

6

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.

Community
  • 1
  • 1
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 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 pord,pre-prod ? – nicoulaj Feb 19 '10 at 15:07
2

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

Community
  • 1
  • 1
Peter Lynch
  • 525
  • 5
  • 9
  • 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. – nicoulaj Feb 25 '10 at 22:56