Build Profiles in Maven

Profile in maven is nothing but subset of elements which allows to customize builds for particular environment. Profiles are also portable for different build environments.

Build environment basically means a specific environment set for production and development instances. When developers work on development phase, they are intend to use database from the production instance and for the production phase, the live database will be used.

So, in order to configure these instances maven provides the feature of build profiles. Any no. of build profiles can be configured and also can override any other settings in the pom.xml

These defined profiles have the ability to modify the pom.xml during the build time. I.e. to configure separate environments for development and production instances. Based on the parameters passed, the corresponding profiles are activated accordingly. E.g. profiles can be set for dev, test and production phases.

Types of build profiles

The below table shows the types of build profiles in Maven :

Build Profile TypeDefined in
Per projectpom.xml
Per User/DeveloperMaven settings.xml (%USER_HOME%/.m2/settings.xml)
GlobalMaven global settings.xml (%M2_HOME%/conf/settings.xml)

Build Portability

As mentioned above, different environments can be set up based on the requirements for a given project. So, with this the portability of a given project can be secured and handled effectively.

Build portability can be defined as the ability of a project which can be compiled and deployed successfully across different set of environments which also involves the applying different environmental configurations for the same. Any portable project should always tend to work without any customization of any properties.

And Any portable project will always eliminates the complexities and issues associated to contributing to a project.

Activating profiles

Below are ways in which build profiles of maven can be activated or triggered :

  • Explicitly using commands
  • Maven settings
  • Based on environment variables
  • Operating system settings
  • Present/missing files

Explicitly using commands

                     <copy file="src/main/resources/" 

Maven Settings

<settings xmlns=""
         <name>Internal Artifactory Maven repository</name>

Based on Environment Variables


Operating System Settings

         <name>Windows 7</name>

Present/missing files