Print runtime classpath for java binary rule in bazel

251 views
Skip to first unread message

Aryeh Hillman

unread,
Jun 10, 2022, 6:59:27 PM6/10/22
to bazel-discuss
Is there a way to do this? Something like `println configurations.runtime.resolve()` in gradle.

aryeh

Alex Humesky

unread,
Jun 13, 2022, 9:55:03 PM6/13/22
to Aryeh Hillman, bazel-discuss
One way to do this is something like:

bazel cquery //java/app:App --output=starlark --starlark:expr="'\\n'.join([jar.path for jar in providers(target)['JavaRuntimeClasspathProvider'].runtime_classpath.to_list()])"

The output is:

INFO: Analyzed target //java/app:App (46 packages loaded, 741 targets configured).
INFO: Found 1 target...
bazel-out/k8-fastbuild/bin/java/app/App.jar
bazel-out/k8-fastbuild/bin/java/lib/libLib.jar
bazel-out/k8-fastbuild/bin/java/lib2/libLib2.jar
INFO: Elapsed time: 0.814s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions


for a build like this:

java/app/BUILD:
java_binary(
  name = "App",
  srcs = ["App.java"],
  deps = ["//java/lib:Lib"],
)
java/lib/BUILD:
java_library(
  name = "Lib",
  srcs = ["Lib.java"],
  deps = ["//java/lib2:Lib2"],
  visibility = ["//visibility:public"],
)
java/lib2/BUILD:
java_library(
  name = "Lib2",
  srcs = ["Lib2.java"],
  visibility = ["//visibility:public"],
)

On Fri, Jun 10, 2022 at 6:59 PM 'Aryeh Hillman' via bazel-discuss <bazel-...@googlegroups.com> wrote:
Is there a way to do this? Something like `println configurations.runtime.resolve()` in gradle.

aryeh

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/075d6d34-2d7c-461d-b8e2-08958935c657n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages