Maven Profile: Difference between revisions
Line 45: | Line 45: | ||
:https://github.com/NovaOrdis/playground/blob/master/jboss/infinispan/hotrod-client/pom.xml<br> | :https://github.com/NovaOrdis/playground/blob/master/jboss/infinispan/hotrod-client/pom.xml<br> | ||
</blockquote> | </blockquote> | ||
=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|Active by Default]] below) or by specifying it in the [[#In_Settings|list of active profiles in settings.xml]]. | |||
=Profile Naming Conventions= | =Profile Naming Conventions= |
Revision as of 17:40, 1 March 2017
External
- Introduction to Build Profiles http://maven.apache.org/guides/introduction/introduction-to-profiles.html
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> ...
Examples
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.
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.
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
Activating a Profile
Active by Default
<profile> <id>some-profile</id> <activation> <activeByDefault>true</activeByDefault> </activation> ... </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>
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.
How Can I Tell which Profile is Active?
mvn help:active-profiles