[英]Versioning for Java binaries
I am looking to automatically attach a version number to a Java binary built by Bazel.我希望自动将版本号附加到 Bazel 构建的 Java 二进制文件。 With the following code, I can only generate the file hello-world.jar
when running bazel build //:hello-world
.使用以下代码,我只能在运行bazel build //:hello-world
时生成文件hello-world.jar
。
java_binary(
name = "hello-world",
srcs = glob(["src/main/java/com/bmuschko/**/*.java"]),
main_class = "com.bmuschko.HelloWorld"
)
What I would like to produce is a way to define a version eg 1.2.3 which would automatically produce the file hello-world-1.2.3.jar
similar to other build tools like Maven or Gradle.我想要生成的是一种定义版本的方法,例如 1.2.3,它会自动生成文件hello-world-1.2.3.jar
类似于其他构建工具,如 Maven 或 Gradle。 This functionality doesn't seem to be a built-in feature in Bazel as indicated by issue-1291 .如issue-1291所示,此功能似乎不是 Bazel 中的内置功能。
What's the idiomatic way to implement the described use case?实现所描述的用例的惯用方法是什么?
The current idiomatic approach to rename files in Bazel is through using a simple genrule:当前在 Bazel 中重命名文件的惯用方法是使用一个简单的 genrule:
VERSION = "1.2.3"
genrule(
name = "versioned_hello_world",
srcs = [":hello-world.jar"],
outs = [":hello-world-%s.jar" % VERSION],
cmd = "cp $< $@",
)
To build, run $ bazel build :versioned_hello_world
or $ bazel build :hello-world-1.2.3.jar
.要构建,请运行$ bazel build :versioned_hello_world
或$ bazel build :hello-world-1.2.3.jar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.