Use providers instead of structs for `java_toolchain` tools (#397)

Bazel stores depsets in the fields of provider instances without their `Depset` wrapper objects, but it can't do so for structs. The tool structs of `java_toolchain` (`_javabuilder`, `_header_compiler`, `_header_compiler_direct`, `_bytecode_optimizer` and `_android_linter`) hold up to three depsets each and are retained for as long as the toolchain's configured target. Their fields stay the same, and Bazel's `JavaToolchainTool` reads them through `StructImpl`, which provider instances implement too.

Verified with a heap dump of `bazel build --nobuild //src:bazel-dev` in the Bazel repo with this change overridden in, which no longer retains any `Depset` through a `struct(data, jvm_opts, tool)`.

(ignore-relnotes)

Closes #397

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/397 from fmeum:java-toolchain-tool-provider d9917d12cca97b64cef439ca8e2f9a052af873ad
PiperOrigin-RevId: 1033343641
Change-Id: Idffbac74645ece9b2d04f9a1d5811bd51e4c56f4
1 file changed
tree: 70182985888303d637060eba0b04661b5d1e7422
  1. .bazel_checkout/
  2. .bazelci/
  3. .bcr/
  4. .github/
  5. distro/
  6. examples/
  7. java/
  8. test/
  9. third_party/
  10. toolchains/
  11. .bazelignore
  12. .bazelrc
  13. .gitignore
  14. AUTHORS
  15. BUILD
  16. CODEOWNERS
  17. CONTRIBUTING.md
  18. LICENSE
  19. MODULE.bazel
  20. README.md
  21. renovate.json
  22. WORKSPACE
  23. WORKSPACE.bzlmod
README.md

rules_java

Build status

Java Rules for Bazel https://bazel.build.

Documentation

For a quickstart tutorial, see https://bazel.build/start/java

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/java.

For slightly more advanced usage, like setting up toolchains or writing your own java-like rules, see https://bazel.build/docs/bazel-and-java

Core Java rules

Add a load like:

load("@rules_java//java:java_library.bzl", "java_library")

to your BUILD / BUILD.bazel / *.bzl files

For detailed docs on the core rules, see https://bazel.build/reference/be/java