bazelbuild / bazelbuild/bazel

java_binary: No way to provide dynamic manifest file content

Open
#2,009 11 comments 4 reactions 0 assignees View on GitHub
not stale P3 team-Rules-Java type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

There seems to be no way to provide dynamic content, like build info into `MANIFEST.MF` file in `java_binary` rule. Only [deploy_manifest_lines](https://www.bazel.io/versions/master/docs/be/java.html#java_binary.deploy_manifest_lines) is supported, where only list of static strings can be provided.

In Buck there is `manifest_file` attribute in [`java_binary`](https://buckbuild.com/rule/java_binary.html) rule where a label can be provided.

What people normally want to achieve is to add build version into manifest file. This can be done (since Bazel 0.3.2) with `--workspace_status_command=./tools/workspace-status.sh` option in `.bazelrc` file and this genrule:

```
genrule(
name = "gerrit_plugin_version",
stamp = 1,
cmd = ("grep STABLE_BUILD_GIT_LABEL < bazel-out/stable-status.txt | " +
"cut -d ' ' -f 2 > $@"),
outs = ['gerrit_plugin_version.txt'],
)
```

However, unless I'm missing something obvious, there is no way to merge this version into `MANIFEST.MF` in `java_binary` rule:

```
java_binary(
name = "gerrit_foo_plugin",
main_class = "Dummy",
# TODO(davido): Move this part into manifest
# when Bazel supports manifest file merging
resources = [":gerrit_plugin_version.txt"],
runtime_deps = ["@guava//jar"],
# Only static key value pairs can be added here.
deploy_manifest_lines = ["bar: baz"],
)
```

`gerrit_plugin_version.txt` is included in the root of the plugin JAR:

```
cat gerrit_plugin_version.txt
5a6f4fd-dirty
```

With the above rules we have this content of `META-INF/MANIFEST.MF`:

```
$ bazel build gerrit_foo_plugin_deploy.jar
INFO: Found 1 target...
Target //:gerrit_foo_plugin_deploy.jar up-to-date:
bazel-bin/gerrit_foo_plugin_deploy.jar
INFO: Elapsed time: 0.551s, Critical Path: 0.46s

$ jar -xf bazel-bin/gerrit_foo_plugin_deploy.jar META-INF/MANIFEST.MF
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
bar: baz
Created-By: blaze-singlejar
Main-Class: Dummy
```

What I would like to be able to have instead, is:

```
$ cat META-INF/MANIFEST.MF
[...]
Implementation-Version: 5a6f4fd-dirty
```

Contributor guide

Open the contributing guide

Research direction

Start with the java_binary rule and its deploy_manifest_lines attribute, then review the workspace-status and genrule example in the issue. Determine how generated content could be merged into META-INF/MANIFEST.MF while preserving existing entries. Done means a java_binary can produce an Implementation-Version value such as 5a6f4fd-dirty in the deployed JAR manifest.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.