Tree Artifacts in java_library resources?

96 views
Skip to first unread message

Andrew Psaltis

unread,
Jan 26, 2023, 3:16:23 AM1/26/23
to baze...@googlegroups.com, Ryan Beasley

Hi all,

 

We are currently in the process of updating our internal instance of Bazel 5.2

to 6.  For us, the biggest difference so far is the removal of the

`resource_jars`[1] attribute from the `java_library` rule.  Our situation is

described in detail in [2], but in short, we have several components that

rely on resources embedded into output jars from locations outside the

Maven-style source tree.  Unfortunately, we cannot easily adapt to these

conventions, so we're seeking some alternatives that would solve this issue from

a general sense.

 

One such alternative is stashing the relevant resources in a Tree Artifact and

adding them into the `java_library` `resources` attribute.  Unfortunately, that

doesn't really work -- when tree artifacts are added to `resources`, it looks

like only a directory entry is created, and also at not the path we are looking

for.  This seems to be [3], or perhaps closely related to it.  I can create a

new bug if y'all would like.

 

We are interested in addressing this issue (at least for `resources`) and

contributing it back upstream.  I looked around in the code a little, and it

looks like the `singlejar` tool doesn't know how to recursively enter

directories[4], but there is a way to specify the source-destination mappings.

So, it seems like we could either modify `singlejar` to recurse into directories

specified on its command-line, or modify the relevant action builder[5] to

expand tree artifacts, or perhaps a little bit of both.

 

Do either of these implementation ideas make sense?  Are there others that would

be better?  Any pitfalls worth being aware of?

 

Guidance is greatly appreciated.

 

Thanks!

~Andrew

 

[1]: https://github.com/bazelbuild/bazel/issues/13221

[2]: https://github.com/bazelbuild/bazel/issues/13221#issuecomment-1172953634

[3]: https://github.com/bazelbuild/bazel/issues/11996

[4]: https://github.com/bazelbuild/bazel/blob/7b4acfe5bf510a887c7efa021f57b8f7bf5a0713/src/tools/singlejar/output_jar.cc#L945-L960

[5]: https://github.com/bazelbuild/bazel/blob/7b4acfe5bf510a887c7efa021f57b8f7bf5a0713/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java#L162-L169

Reply all
Reply to author
Forward
0 new messages