What is Maven Build Profiles?

Maven Build Profiles

Maven Profiles: Profile is a subset of elements or configuration value which allows to customize builds for environment such as production or development environments.

Profiles are defined in pom.xml file using its activeProfiles/profiles elements. Profiles modify the Pom at build time and are used to give parameters different target environments (i.e. to configure separate environments for development and production instances. Based on the parameters passed, the corresponding profiles are activated accordingly.)

Types of Build Profile : There are three types of build profile.

  1. Per Project :This is defined in pom.xml.
  2. Per User/Developer :Maven settings.xml (%USER_HOME%/.m2/settings.xml).
  3. Global :Maven global settings.xml (%M2_HOME%/conf/settings.xml).


Activating Profiles: The following are the number of ways to activate the build profile.

  1. Use of command on the input console explicitly.
  2. Through maven settings
  3. Through the environment variables
  4. OS settings i.e. windows, linux, Unix etc.
  5. Through properties or setup files.

1. Explicit Profile Activation:  In explicitly profile activation, we attached the maven-antrun-plugin: run goal to test the phase which will allow us to print the given text messages to different profiles chosen for execution. We will be using pom.xml file to define different profiles as default, sit, uat and prod and will activate profile at eclipse console which executing it as Run as -> Maven build.

                     <echo>Using app.test.properties</echo>
                     <copy file="src/main/resources/app.test.properties"


2. Profile Activation through Maven Settings: In this we will do some changes in maven settings.xml file which is available at %USER_HOME%/.m2 directory on your system is updated. If settins.xml file is not there, then create a new one.

We can add this using active profiles node as shown below.

<settings xmlns = "http://maven.apache.org/POM/4.0.0"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         <name>Internal Artifactory Maven repository</name>

3. Profile Activation through Environment Variables: In this case, we provide profile activation details through environment variables. Therefore, we need to remove setting from maven settings.xml file and update the test profile mentioned in pom.xml. Add activation element to profile element as shown below. The ‘test’ profile will pick up the system property ‘env’ which has the value as ‘uat’.


4. Profile Activation through Operating System: In this case, activation element include OS details. This test profile is triggered when the system is Linux.


I hope this tutorial will be helpful for you to learn the maven profiles.





Leave a Comment