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.

  • How to Add a File in .git Directory to Track It?
  • How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?
  • Use 'pull' or 'merge' to merge local branches?
  • Working with a forked git repository, except I cloned the public repo URL, not the private URL
  • why should I delete feature branches when merged to master
  • How can I re-fetch the revisions of a newly specified branch with git-svn
  • 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.

  • GitHub Webhook Secret Never Validates
  • How to forcefully delete a remote branch in GitHub?
  • How do I view all Git pull requests across repositories in TFS?
  • How to install Git on Solaris 10?
  • How to put Excel VBA into git
  • Creating new projects from an existing “boilerplate” repo
  • 2 Solutions collect form web for “select maven profile based on git branch”

    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.

    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)

    Git Baby is a git and github fan, let's start git clone.