maven build profiles

Maven build profiles

Maven build profiles provides the facility to build project using different configurations. Instead of creating two separate POM files, we can just specify a profile with the different build configuration and build the project with this build profile when needed.

The profiles element is used to specify the maven build profiles inside the POM file. Each build profile is nested inside a profile element. The elements inside the profile element will override the values of the elements with the same name further up in the POM. The activation element inside the profile element is used to describe the condition that triggers the build profile to be used. We can use settings.xml file to tell maven which profile is to be executed. Another way is to add -P profile-name to the Maven command line.

Example:

<project 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/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.tutorialspointexamples.application1</groupId>
  <artifactId>java-web-crawler</artifactId>
  <version>1.0.0</version>
 
  <profiles>
      <profile>
          <id>test-app</id>
          <activation>...</activation>
          <build>...</build>
          <modules>...</modules>
          <repositories>...</repositories>
          <pluginRepositories>...</pluginRepositories>
          <dependencies>...</dependencies>
          <reporting>...</reporting>
          <dependencyManagement>...</dependencyManagement>
          <distributionManagement>...</distributionManagement>
      </profile>
  </profiles>
 
</project>