Search code examples
bazelbazel-rulesbazel-java

How do I pass arguments to Bazel java wrapper?


I’m using Bazel to build JanusGraph. For Janusgraph to find all the config files it needs to have them on the classpath. It finds the files via File class but that can’t read from a jar. Basel docs say you can configure the wrapper it generates to prepend to the classpath:

The wrapper script accepts several unique flags. Refer to //src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt for a list of configurable flags and environment variables accepted by the wrapper.

That file mentioned flag —-main_advice_classpath which seems to be exactly what I need. But I can’t figure out how to use it. I’ve passed the argument to several of the arguments in the java_binary target but nothing has worked. How do I pass arguments to configure the wrapper that runs the Java binary?


Solution

  • G'day! It ends up being the same as this answer.

    You just need to use bazel run <target name> -- --main_advice_classpath=<arg> <other args>

    You can also pass it directly if you run the wrapper directly, e.g. bazel-bin/path/to/target/wrapper --main_advice_classpath=... ...