Maven - Can I reference profile id in profile definition?

Viewed 35791

I've set profiles in a pom.xml, like shown as follows:

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

Question:

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

3 Answers

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 
Related