How do I activate a profile based on the value of a property?
Author: Deron Eriksson
Description: This maven tutorial describes how to activate a profile based on the value of a property.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


A mavenSW profile can be activated by the value of a property. As an example, the following fragment of my user settings.xml file shows two profiles. The first profile can be activated if the property called 'prop' exists and has a value of 'one'. The second profile can be activated by the presencse of the property 'prop' with the value of 'two'.

Profiles in settings.xml

...
	<profiles>
		<profile>
			<id>one.profile</id>
			<activation>
				<property>
					<name>prop</name>
					<value>one</value>
				</property>
			</activation>
			<properties>
				<my.property>value from one.profile</my.property>
			</properties>
		</profile>
		<profile>
			<id>two.profile</id>
			<activation>
				<property>
					<name>prop</name>
					<value>two</value>
				</property>
			</activation>
			<properties>
				<my.property>value from two.profile</my.property>
			</properties>
		</profile>
	</profiles>
...

In one of my projects, I'll call maven, setting the 'prop' property to be 'one' via '-Dprop=one'. To display the active profiles, I'll call the "help:active-profiles" goal:

mvn -Dprop=one help:active-profiles

The output of this maven command is shown below, where we can see that the 'one.profile' profile is active as a result of the 'prop' property being set to 'one'.

Console output from 'mvn -Dprop=one help:active-profiles'

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO]    task-segment: [help:active-profiles] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:active-profiles]
[INFO] 
Active Profiles for Project 'com.maventest:aproject:jar:1.0-SNAPSHOT': 

The following profiles are active:

 - one.profile (source: settings.xml)



[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sun Feb 17 01:52:39 PST 2008
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------