javabazelbazel-java

Is it possible to use bazel query to output the full syntax for an implicit (or any) rule?


My goal is to write a new explicit rule that is equivalent to an internal rule but with a small modification (embed certain dependencies but not others).

Suppose I have a rule like the following:

java_binary(
    name = "cipher_jar",
    srcs = glob([
        "*.java",
    ]),
    ...
)

There's an implicit rule which looks like the following:

bazel query  "//cipher:cipher_jar_deploy.jar"

Is there some query I can run to force bazel to output something equivalent to the java_binary rule above for this implicit rule?


It looks like using --output=build just gets me the original rule, while I want a rule that explicitly tells bazel to embed dependencies.


Solution

  • The logic for the builtin Bazel Java rules such as java_binary and java_library is written in Java and lives in the Bazel binary. However, there is a Starlark API for many of the primitive operations used by Java rules. Those may be used to make custom Java rules. Indeed, there is an ongoing project to transparently replace the builtin Bazel Java rules with a Starlark implementation.