Previous – Chapter 5

Maven Tutorial – Chapter 6

What is Maven build profile?

Maven Build Profile 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 Type Defined in
Per project pom.xml
Per User/Developer Maven settings.xml (%USER_HOME%/.m2/settings.xml)
Global Maven 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.

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:

[xml]
<settings xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/settings-1.0.0.xsd">

   <mirrors>
     <mirror>
         <id>com.testorg.companyname</id>
         <name>Internal Artifactory Maven repository</name>
         <url>http://repo1.maven.org/maven2/</url>
        <mirrorOf>*</mirrorOf>
     </mirror>
   </mirrors>
   <activeProfiles>
     <activeProfile>test</activeProfile>
   </activeProfiles>
</settings>
[/xml]

[xml]
<profile>  
<id>test</id>
<activation>    
<property>        
<name>env</name>        
<value>test</value>    
</property>  
</activation>
</profile>
[/xml]

[xml]

<profile>  
<id>test</id>  
<activation>    
<os>        
<name>Windows 7</name>        
<family>Windows</family>        
<arch>x86</arch>
<version>5.1.2600</version>
</os>
</activation>
</profile>
[/xml]

Leave a Reply

Your email address will not be published. Required fields are marked *