Can Bazel aspects access the current target's java_common.provider

402 views Asked by At

As part of our efforts to create a bazel-maven transition interop tool (that creates maven sized jars from more granular sized bazel jars), we want the aspect that runs on bazel build to access the target's java_common.provider in order to fetch the jars and ijars from it.

Is that possible?

1

There are 1 answers

4
davidstanke On BEST ANSWER

The short answer is yes, that's possible.

You can use the java_common module in an aspect implementation the same way you would use it in a rule implementation.

From the documentation on java_common.provider:

  • java_common.provider.compile_jars and java_common.provider.transitive_compile_time_jars refer to the ijars used at compilation time
  • java_common.provider.transitive_runtime_jars refer to the full jars used at runtime.

The full jars at compilation time are not yet available, but someone is working on exposing this feature. (Issue #3528 on GitHub.)

Make sure you also read the blog post on this topic: https://blog.bazel.build/2017/03/07/java-sandwich.html