Attempt to fix missing class error by not using tree artifacts for bootclasspath (#340) A few times a year across many thousands of builds we encounter a rare error about the `DumpPlatformClassPath` class being missing. Our Bazel setup uses dynamic execution, builds without the bytes, remote execution + remote caching, and path mapping. The error we encounter is as follows: ``` Error: Could not find or load main class DumpPlatformClassPath Caused by: java.lang.ClassNotFoundException: DumpPlatformClassPath ``` I'm guessing that this is happening due to some kind of Bazel bug that happens with our Bazel setup and tree artifacts, i.e., declare_directory. Best I can tell this is happening because the `DumpPlatformClassPath.class` file is somehow not materializing correctly. I'm not 100% confident about that, but it's my leading hypothesis at this point in time. This commit changes the actions in `bootclasspath.bzl` to not rely on tree artifacts. Instead, they rely JDK 11+'s ability to launch single-file programs (introduced in JEP 330). This avoids the `javac` action and `declare_directory` previously required to compile `DumpPlatformClassPath`. Problem is this makes rules_java not compatible with JDK's older than 11. I'm very open to alternative solutions to this, but I haven't yet come up with a robust, cross platform solution that avoids tree artifacts while also maintaining compatibility with JDKs older than 11. I wanted to open this PR to get some discussion going. Closes #340 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/340 from lucidsoftware:bootclasspath-avoid-tree-artifact 34809e22c0022d4bb72088c0b1cfc864ea0cfb31 PiperOrigin-RevId: 880851895 Change-Id: I04c7142981a22b9f4995f25e2789ac6aa2aaf097
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