Put current git branch to project version

I want to put the current git branch into the version field in pom xml. I found some post in the internet suggesting to do something like:

<version>${scm.version}</version>

but this seems not to work with git. Are there any other solutions?

  • What is the difference between 'git remote update', 'git fetch' and 'git pull'?
  • git filter-branch - discard the changes to a set of files in a range of commits
  • How do I programmatically determine if there are uncommited changes?
  • How do I exit the results of 'git diff' in Git Bash on windows?
  • Git merge two remote branches in one repository
  • Move one Git repo into a subfolder of another with branches
  • Installing Git on Eclipse
  • Difference between GIT and CVS
  • Converting a repository from git to subversion
  • Gitweb: How I see source code in tree view with color
  • How to change the current branch to master in Egit?
  • Unable to push to Heroku after being able to do do
  • 2 Solutions collect form web for “Put current git branch to project version”

    Yes, use the git commit id plugin for maven

    It’s pretty straightforward. You can use it to get the git branch with

    ${git.branch}
    

    So in your case it would go:

    <version>${git.branch}</version>
    

    i created a plugin for this behavior (and by extend to link sonar to my maven projects).

    The only thing you need to do is

    add following plugin to your pom.xml

    <plugin>
        <groupId>com.viae-it.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
         <version>LATEST</version>
    </plugin>
    

    call the plugin to set the git branch

    mvn com.viae-it.maven:sonar-maven-plugin:set-git-branch
    

    then you can use the sonar.branch property

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