Select maven profile based on git branch

Is it possible to select a profile based on the current git branch?

For example, if you are in the main branch, he selects the profile "production". If it is a development branch, it selects a development profile.

I found the mavanagaiata plugin that provides the mvngit.branch property but cannot be used in the <profiles> section.

Is something like this possible? Or are there better ways? I want a simple way to automatically select the correct profile depending on which branch is being built.

+4
source share
2 answers

Make profile activation a file. Then create the file only in the appropriate branch, so when switching branches the file will appear or disappear, this will affect the activation of the profile.

However, I feel that it is a bad idea to choose a maven profile based on the git branch.

+1
source
  • Use the profile id just like the git branch.
  • Run maven with the appropriate profile:

    mvn clean deploy -P $ (git rev-parse --abbrev-ref HEAD)

+3
source

All Articles