将当前的 git 分支放到项目版本中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21553304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:41:25  来源:igfitidea点击:

Put current git branch to project version

gitmavenversioning

提问by markus

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:

我想把当前的 git 分支放到 pom xml 的 version 字段中。我在互联网上发现了一些帖子,建议执行以下操作:

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

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

但这似乎不适用于 git。还有其他解决方案吗?

回答by Arnaud Potier

Yes, use the git commit id plugin for maven

是的,使用mavengit commit id 插件

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

这很简单。您可以使用它来获取 git 分支

${git.branch}

So in your case it would go:

所以在你的情况下它会去:

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

回答by Vandeperre Maarten

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

我为此行为创建了一个插件(并通过扩展将声纳链接到我的 maven 项目)。

The only thing you need to do is

你唯一需要做的就是

add following plugin to your pom.xml

将以下插件添加到您的 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

调用插件设置git分支

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

then you can use the sonar.branch property

那么你可以使用 sonar.branch 属性