In my previous post, I explained how to create profiles
and execute them while creating artifacts.
But there is some situation, where you need to provide customizations based
on some variables like operating system, jdk version etc.,
You can achieve this by using profile activation.
The following configuration will trigger the profile when
the JDK's version starts with "1.8" (eg. "1.8.0_08",
"1.8.2_07", "1.8"):
<profiles> <profile> <activation> <jdk>1.8</jdk> </activation> ... </profile> </profiles>
You can also specify the ranges while activating the properties.
(,) : Exclusive Quantifier
[,] : Inclusive Quantifier
(3, 8) : Version should be greater than 3 and less than
8.
(3, 8] : Version should be greater than 3 and less than
or equal to 8.
[3, 8) : Version should be greater than or equal to 3 and
less than 8.
[3, 8] : Version should be greater than or equal to 3 and
less than or equal to 8.
[3, ] : Version
should be anything greater than or equal to 3
[, 8] : Version
should be anything less than or equal to 8
<profiles> <profile> <activation> <jdk>[1.3,1.6)</jdk> </activation> ... </profile> </profiles>
Activate profile based on operating system information.
<profiles> <profile> <activation> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> </activation> ... </profile> </profiles>
Activate profile, if there is a system property
'myAppVersion' is there.
<profiles> <profile> <activation> <property> <name>myAppVersion</name> </property> </activation> ... </profile> </profiles>
Activate profile, when the system property
"myAppVersion" is specified with the value
"DocumentStorage"
<profiles> <profile> <activation> <property> <name>myAppVersion</name> <value>DocumentStorage</value> </property> </activation> ... </profile> </profiles>
Activate a profile on the absence of a property.
Below profile will be activated, when the system variable
'myApp.oldVersion' is not presented during maven execution.
<profiles> <profile> <activation> <property> <name>!myApp.oldVersion</name> </property> </activation> ... </profile> </profiles>
Let’s see a detailed example.
<profile> <activation> <activeByDefault>false</activeByDefault> <jdk>1.8</jdk> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>myAppVersion</name> </property> </activation> </profile>
<activeByDefault>false</activeByDefault>
This profile is not activated by default
<jdk>1.8</jdk>
This profile will only be active for JDK versions that
begin with "1.8".
<os>
<name>Windows
XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
This profile is specific to Windows XP X86 version
5.1.2600.
<property>
<name>myAppVersion</name>
</property>
This profile is activated, if the system property 'myAppVersion'
exists in maven execution.
No comments:
Post a Comment