Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select maven profile based on git branch

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

For example, if you are in the master branch, it selects the 'production' profile. If it is the develop branch, it selects the 'development' profile.

I found the mavanagaiata plugin which provides the mvngit.branch property but it can not be used in the <profiles> section.

Is something like this possible? Or are there better ways? I want an easy way to automatically select the correct profile depending on the branch being build.

like image 213
rve Avatar asked Jan 15 '23 16:01

rve


2 Answers

  1. Use profile ID the same as your git branch.
  2. Run maven with corresponding profile:

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

like image 185
ursa Avatar answered Jan 21 '23 07:01

ursa


Make the profile activation by a file. Then create the file in a corresponding branch only, so that when you switch branches the file will appear or disappear, it will affect the profile activation.

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

like image 22
kan Avatar answered Jan 21 '23 06:01

kan