Replacement for resource_jars in Bazel 5?

336 views
Skip to first unread message

Gunnar Wagenknecht

unread,
Mar 24, 2022, 6:45:39 AM3/24/22
to bazel-discuss
Hi,

Bazel 5 dropped support for `resource_jars` on `java_library`. It's no longer possible to let Bazel package resources automatically in the jar. I came up with a possible alternative using `rules_pkg` to generate a jar and `java_import` to make it available as runtime dependency.

The problem I face is that this doesn't seem to work as expected. I do see the resources getting packaged properly. But the `java_binary` seems to be incapable of locating the resources.

An example change can be observed here:


To reproduce:
git clone g...@github.com:salesforce/bazel-java-builder-template.git
cd bazel-java-builder-template/examples/001-simple
bazel build :all


The produced java_binary is execute in a rule like this:


    ctx.actions.run(
        ..
        executable = ctx.executable._mybuilder,
        ...
    )

I can see the resource jars added to the run files manifest. However, if I look into the generated launcher script, I do not see the resource jar being added there to the CLASSPATH variable.

Is there anything else necessary to add the resource jar to the runtime deps?

-Gunnar


-- 
Gunnar Wagenknecht
gun...@wagenknecht.org, http://guw.io/



Gunnar Wagenknecht

unread,
Mar 24, 2022, 7:39:16 AM3/24/22
to bazel-discuss
Reply all
Reply to author
Forward
0 new messages