简体   繁体   English

将“git describe” output 传递给 Java 代码

[英]pass “git describe” output to Java code

Is there a way to pass the output of git describe --tag to my Java application at compile time?有没有办法在编译时将 git 的git describe --tag给我的 Java 应用程序? I'd like to use that in my about box to display version info.我想在我的关于框中使用它来显示版本信息。 I'm using Eclipse to build, but I can use ant if necessary.我正在使用 Eclipse 来构建,但如果需要,我可以使用 ant。

With C code, I can pass -D'REV="$(shell git describe --tag)"' to my gcc compiler, and my code can pick that up.使用 C 代码,我可以将-D'REV="$(shell git describe --tag)"'传递给我的 gcc 编译器,然后我的代码就可以获取它。 I'm hoping there's something similar in Java.我希望在 Java 中有类似的东西。

If ant is acceptable, it supports a similar command line option .如果ant是可以接受的,它支持类似的命令行选项

As a concrete example, this line in an ant script作为一个具体的例子, ant脚本中的这一行

<echo>property: ${property}</echo>

when invoked with the following command,当使用以下命令调用时,

$ ant -Dproperty="$(git --version)"

produces the following output on the console,在控制台上生成以下 output,

[echo] property: git version 1.7.5.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM