Maven Profile

From NovaOrdis Knowledge Base
Jump to navigation Jump to search




A profile is an alternative set of configurations which set or override default values. Profiles allow to customize a build for different environments. Profiles can be defined:

  • per project in the pom.xml file. These are called inline profiles and they are preferred, as they have a better chance of preserving the portability.
  • per-user in ${user.home}/.m2/settings.xml. These are a truncated version of the inline profile, only containing <activation>, <repositories>, <pluginRepositories> and <properties> elements. They are truncated because they concern themselves with the build system as a whole, not about individual project object model setting. Note that if a profile is active from settings.xml, its values will override any equivalently ID'd profiles in a POM or profiles.xml.
  • global in ${maven.home}/conf/settings.xml

Each profile is identified with an identifier. Profiles customizes the build for different environments (e.g. production or development, different operating systems, different JDK versions, etc.)

The power of a profile comes from its ability to modify some values only under certain circumstances. Those circumstances can be specified in a variety of ways - see Activating a Profile below.

An example of profile:

             <name>Some Repository</name>


Active Profile

More than one profile can be active at a time. A profile can be "activated" by declaring it so (see Active by Default below) or by specifying it in the list of active profiles in settings.xml, or via other methods. For more details see Activating a Profile below.

How Can I Tell which Profile is Active?

mvn help:active-profiles

Effective Settings when More than One Profile is Active


Profile Naming Conventions

Use the common system property trigger as part of the name for the profile. If a profile is triggered by the system property env, valid profile names are env-dev, env-stage, etc.

A profile ID may include spaces.

Build Configuration that Can Be Modified in a Profile

Inline Profiles

An inline profile can modify the following POM elements:

  • <repositories>
  • <pluginRepositories>
  • <dependencies>
  • <plugins>
  • <properties> (not actually available in the main POM, but used behind the scenes, for more details see section "Profiles and Properties")
  • <modules>
  • <reporting>
  • <dependencyManagement>
  • <distributionManagement>
  • a subset of the <build> element, which consists of:
    • <defaultGoal>
    • <resources>
    • <testResources>
    • <finalName>

Profiles and Properties


The properties declared as such are accessible form a POM if the declaring profile is active.

Also see:

Maven Concepts - Variables

Standard Properties

Download Sources for all Dependencies


Also see

Download Sources with the Class JAR Files

Download Javadoc for all Dependencies


Activating a Profile

Active by Default


Command Line

The profile can be activated explicitly on command line with -P:

mvn -Pproduction clear install

When this options is used, the specified profiles are activated in additions of those specified in the <activeProfiles> element of settings.xml.

In Settings

The active profiles are specified in settings.xml:


The list contains <activeProfile> elements, where each element contains a profile id. Any profile referred here will be active regardless of any environment settings. If no matching profile is found, nothing will happen. If the profiles mentioned here are not found, the execution will continue as normal.

By a System Property

mvn -Denv=test ...

Other Methods

A profile can also be triggered based on environment variables, OS settings, or present or missing files. The trigger is specified in the <activation> section of the profile. Activation occurs when all specified criteria have been met.


         <name>Windows XP</name>

For more details, see: