Profiles in Maven

Build process may differ based upon environments like development, production etc. It may also differ based on operating system. So how to configure maven so that based on certain conditions, specific build process should be used? That’s when Profiles come in to picture. With the help of Profile, we can execute the build process with required tweaks. We can define profiles in 2 places.
  • Settings.xml
  • POM.xml
Below xml lines explain how we can declare profiles. Each profile is given unique id. As shown in below example, we have defined 2 profiles – windows-build and unix-build. Based upon type of OS, particular profile will be used to complete the build process. Please note that we can manage plugins, dependencies within each profile differently.
 
<profiles>
<profile>
<id>windows-build</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>

</profile>

<profile>
<id>unix-build</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
</profile>
</profiles>
Sometimes, we might need to activate specific profile by default. For that, you can use below lines of code.
 
<activation>
<activeByDefault>true</activeByDefault>
</activation>
You can also activate the profile at command line using below statements. Below line will choose windows-build profile.
 
mvn test -P windows-build
Below line will choose all profiles except xyz to complete the build process.
 
mvn test -P !xyz

Web development and Automation testing

solutions delivered!!