Maven Profile: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:


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:
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 <tt>pom.xml</tt> file - these are called ''inline'' profiles and they are preferred, as they have a better chance of preserving the portability.
* per project in the <tt>pom.xml</tt> file - these are called <span id="inline_profile">''inline'' profiles</span> and they are preferred, as they have a better chance of preserving the portability.
* per-user in <tt>${user.home}/.m2/settings.xml</tt>
* per-user in <tt>${user.home}/.m2/settings.xml</tt>
* global in <tt>${maven.home}/conf/settings.xml</tt>
* global in <tt>${maven.home}/conf/settings.xml</tt>
Line 39: Line 39:
...
...
</pre>
</pre>


=Build Configuration that Can Be Modified in a Profile=
=Build Configuration that Can Be Modified in a Profile=

Revision as of 18:56, 26 October 2016

External

Internal

Overview

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
  • 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.)

An example of profile:

...
<profiles> 
   <profile>
     <id>production</id>
         <build>
            <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <configuration>
                      <debug>false</debug> 
                      <optimize>true</optimize>
                  </configuration>
                </plugin>
            </plugins>
         </build>
   </profile>
 </profiles>
...

Build Configuration that Can Be Modified in a Profile

Inline Profiles

An inline profile

Activating a Profile

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:

<settings>
  ...
  <activeProfiles>
    <activeProfile>blue</activeProfile>
  </activeProfiles>
  ...
</settings>

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.