views:

270

answers:

2

In pom.xml I have set o profiles like this:

<profile>
<id>profileId1</id>
    <build>
        <filters>
            <filter>src/main/filters/profileId1.properties</filter>
        </filters>
// rest of the profile 
</profile>
<profile>
<id>profileId2</id>
    <build>
        <filters>
            <filter>src/main/filters/profileId2.properties</filter>
        </filters>
// rest of the profile
</profile>

Is there any way I could extract this piece from all the profiles, so there is no need to repeat this for every profile (and possibly misspell it)?

A: 

You can put the profiles in a parent pom.

Andrew Aylett
+1  A: 

According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).

So just try ${project.profiles[0].id}, ${project.profiles[1].id}, etc.

If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:

<profile>  
  <id>profile-profileId1</id>  
  <activation>
    <property>
      <name>profile</name>
      <value>profileId1</value>
    </property>
  </activation>
  <build>  
    <filters>  
      <filter>src/main/filters/${profile}.properties</filter>  
    </filters>  
    // rest of the profile  
</profile>

To activate this profile, you would type this on the command line:

mvn groupId:artifactId:goal -Dprofile=profileId1 
Pascal Thivent