I\'ve set profiles in a pom.xml
, like shown as follows:
profileId1
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
With maven 2.2.1 and later, I was able to get the ID of the first active profile using:
${project.activeProfiles[0].id}
Of course this fails if there is not a least one active profile.
Using the
${project.profiles[0].id}
as suggested by Pascal did not work for me.
Hint: While investigating this, I really started to love mvn help:evaluate
.
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