A profile can be specified in pom.xml
or settings.xml
. Each profile may be created for a specific purpose; for instance, to run on a particular platform or to run in an integration environment. All profiles may not need to run in all cases. Maven provides a mechanism to activate and deactivate a profile as required.
Let's perform the following steps to activate/deactivate a Maven profile:
activeByDefault
element:<activeByDefault>false</activeByDefault>
mvn help:active-profiles
The output for the preceding command is shown as follows:
[INFO] --- maven-help-plugin:2.2:active-profiles (default-cli) @ project-with-profile --- [INFO] Active Profiles for Project 'com.packt.cookbook:project-with-profile:jar:1.0-SNAPSHOT': The following profiles are active:
<activeByDefault>true</activeByDefault>
mvn help:active-profiles
The output for preceding command is shown as follows:
The following profiles are active: - dev (source: com.packt.cookbook:project-with-profile:1.0-SNAPSHOT)
Profiles can be triggered in one of the following ways:
mvn –P dev package
This invokes the dev
profile
<active>
property to true
. If activated, when the project is built, the profile is invoked:<activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>
<profile> <activation> <property> <name>debug</name> </property> </activation> ... </profile>
If the system property debug
is defined and has any value, then the profile is activated
<profile> <activation> <os> <family>Windows</family> </os> </activation> ... </profile>
target/site
file is missing:<profile> <activation> <file> <missing>target/site</missing> </file> </activation> </profile>
3.144.17.128