Activate Maven Profile by Property
June 12, 2021
On this page we will learn to activate Maven profile by property. Maven provides <property>
element that is used within <activation>
element. Property name and value can be specified using <name>
and <value>
elements.
<activation> <property> <name></name> <value></value> </property> </activation>
System Property debug
1. Here we will activate a profile for system property 'debug'. If the system property 'debug' is defined, the below profile will be activated.
pom.xml
<project> ------ <profiles> <profile> <id>debug_profile</id> <activation> <property> <name>debug</name> </property> </activation> <build> <resources> <resource> <directory>src/main/resources/debug-files</directory> </resource> </resources> </build> </profile> ------ </profiles> </project>
src/main/resources/debug-files
<activation> <property> <name>!debug</name> </property> </activation>
<activation> <property> <name>debug</name> <value>!true</value> </property> </activation>
To activate profile by property we run Maven command as following.
mvn clean install -Ddebug=false
System Property environment
Find the code to use system property 'environment' .
pom.xml
<project> ------ <profiles> <profile> <id>env_profile</id> <activation> <property> <name>environment</name> <value>prod</value> </property> </activation> <build> <resources> <resource> <directory>src/main/resources/prod-files</directory> </resource> </resources> </build> </profile> ------ </profiles> </project>
mvn clean install -Denvironment=prod