Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Profiles

Profiles provide the conditional behaviours of the POM and allows for different builds depending on its properties. A couple of the usual properties used are the JDK, and the operating system. Furthermore, profiles can be activated depending on the existence of particular files.

Generic Property Activation

You can activate a profile when a specific system property is set. Note only properties set on the Maven command line can activate profiles. Properties set in the POM, the parent POM, or other profiles have no effect.

To activate a profile when a certain property has a certain value (in this case myproperty=myvalue):

Code Block
<profiles>
  <profile>
    <activation>
      <property>
        <name>myproperty</name>
        <value>myvalue</value>
      </property>
    </activation>
    ...
  </profile>
  ...
</profiles>

To activate a profile when a certain property exists (regardless of value):

Code Block
<profiles>
  <profile>
    <activation>
      <property>
        <name>myproperty</name>
      </property>
    </activation>
    ...
  </profile>
  ...
</profiles>


JDK Activation


OS Activation

To configure the activation via the operating system, you can specify at least one out of four items - the project name, family, architecture, and version.

The Profile OS activation part is shown below:

Code Block
<profiles>
  <profile>
    <activation>
      <os>
        <name>windows xp</name>
        <family>windows</family>
        <arch>x86</arch>
        <version>5.1</version>
      </os>
    </activation>
    ...
  </profile>
  ...
</profiles>

For the family, architecture, and version properties, these are checked by comparing these values against System.getProperties( "os.name" ), System.getProperties( "os.arch" ), System.getProperties( "os.version" ) respectively. The legal values for these tags are limited to those held by the System properties.

However, for the family property, a range of possible values can be used:

Family Value

Condition for Activation

windows

if OS name contains the word "windows"

os/2

if OS name contains the word "os/2"

netware

if OS name contains the word "netware"

dos

if OS family is not "netware", and its path separator is ";"

mac

if OS name contains the word "mac"

tandem

if OS name contains the word "nonstop_kernel"

unix

if OS family is not "openvms" and not "mac" which names does not end with "X", and its path separator is ":"

win9x

is OS family is "windows" and OS name contains "95", "98", "me", or "ce"

z/os

if OS name contains the word "z/os" or "os/390"

os/400

if OS name contains the word "os/400"

openvms

if OS name contains the word "openvms"

Warning
titleWarning

For Maven versions prior to 2.0.6, you need to declare your OS family, name, arch and version all in lower case (see MNG-2814).

File Activation 

Controlling activation upon the existence of specific files:

Code Block
<profiles>
  <profile>
    <activation>
      <file>
        <exists>myfile</exists>
      </file>
    </activation>
    ...
  </profile>
  ...
</profiles>

Controlling activation upon the absence of specific files:

Code Block
<profiles>
  <profile>
    <activation>
      <missing>
        <exists>myfile</exists>
      </missing>
    </activation>
    ...
  </profile>
  ...
</profiles>

The definition of the path does not support use of properties, settings or environment variables for Maven 2.0.4. Do not try anything of the form <exists>${user.home}/.m2/com/oracle/ojdbc</exists> instead you will need to hard code the complete path.

Others

Negation

Prepend "!" on property name, os family, os name, os version and os arch to negate.

Meaning

Code Block
<profiles>
  <profile>
    <activation>
      <property>
        <name>!myproperty</name>
      </property>
    </activation>
    ...
  </profile>
  ...
</profiles>

gets executed when myproperty is not defined. And

Code Block
<profiles>
  <profile>
    <activation>
      <os>
        <name>!windows xp</name>
        <family>!windows</family>
        <arch>!x86</arch>
        <version>!5.1</version>
      </os>
    </activation>
    ...
  </profile>
  ...
</profiles>

gets evaluated as true when

Code Block
name != "windows xp" AND family != "windows" AND arch != "x86" AND version != 5.1

Active by Default 

Set to true to activate by default