Maven Tutorial - Maven Build Profile

Maven build profiles is a set of configuration values which allows us to build our project using different configurations.

We can use Maven build profile to set or override default values of Maven build.

We can use build profile to customize build for different environments such as production vs test environments.

We can set different database connection URL for testing and production environments.

Profiles are specified in pom.xml file using its profiles elements and are triggered in variety of ways.


<project ...






A build profile overrides the settings in the POM file when executing under that build profile.

The elements inside the profile element will override the values further up in the POM.

The activation element inside the profile element describes the condition to trigger this build profile to be used.

One way to choose the profile is in the settings.xml file. We can set the active profile there.

Another way is to add -P profile-name to the Maven command line.


Activations are the key of a profile.

An activation element specifies to condition to modify the basic POM. Here is an example.

<project xmlns=""
          <name>Windows XP</name>

Activation occurs when one or more of the specified criteria have been met.

When the first positive condition is encountered, processing stops and the profile is marked as active.

jdkactivation has a built in, Java-centric check in the jdk element. This will activate the profile if the test is run under a jdk version number that matches the prefix given.
osThe os element can define some operating system specific properties.
propertyThe profile will activate if Maven detects a property of the corresponding name=value pair.
fileA given filename may activate the profile by the existence of a file, or if it is missing.

To see which profile will activate in a certain build, use the maven-help-plugin.

mvn help:active-profiles