Tree Artifacts in java_library resources?

Skip to first unread message

Andrew Psaltis

Jan 26, 2023, 3:16:23 AM1/26/23
to, 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.










Reply all
Reply to author
0 new messages