10

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?

markus
  • 5,758
  • 13
  • 39
  • 63
  • Possible duplicate of [Deriving maven artifact version from git branch](https://stackoverflow.com/questions/13583953/deriving-maven-artifact-version-from-git-branch) – Aldian Sep 17 '18 at 15:33

2 Answers2

18

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>
Arnaud Potier
  • 1,682
  • 16
  • 27
-1

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

Vandeperre Maarten
  • 504
  • 1
  • 8
  • 21