How do I activate a profile based on the presence of a property?
Author: Deron Eriksson
Description: This maven tutorial describes how to activate a profile based on the presence of a property.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
It's possible to activate a mavenSW profile based on the presence of a property. As an example, the following 'profiles' section of my user settings.xml file defines two profiles, 'one.profile' and 'two.profile'. The 'one.profile' profile is activated by the presence of a property called 'one' (via the activation.property.name). The 'two.profile' profile is activated by the 'two' property. Profiles in settings.xml... <profiles> <profile> <id>one.profile</id> <activation> <property> <name>one</name> </property> </activation> <properties> <my.property>value from one.profile</my.property> </properties> </profile> <profile> <id>two.profile</id> <activation> <property> <name>two</name> </property> </activation> <properties> <my.property>value from two.profile</my.property> </properties> </profile> </profiles> ... As an example, I'll pass in the 'one' property via the '-Done' command option and call the 'help:active-profiles' goal via the following maven command in one of my maven projects: mvn -Done help:active-profiles The console output of this command is shown here. Notice that the 'one.profile' is listed as an active profile. Console output from 'mvn -Done 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:27:36 PST 2008 [INFO] Final Memory: 2M/6M [INFO] ------------------------------------------------------------------------ As a further test, here I'll activate both the 'one.profile' profile and the 'two.profile' profile: mvn -Done -Dtwo help:active-profiles The resulting output is shown here: Console output from 'mvn -Done -Dtwo 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) - two.profile (source: settings.xml) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Sun Feb 17 01:35:21 PST 2008 [INFO] Final Memory: 2M/5M [INFO] ------------------------------------------------------------------------ Related Tutorials: |