You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there is no clean, public-facing API in Bazel or @bazel_tools to compile a custom JavaBuilder binary with extra Error Prone plugins/checkers (e.g., custom checks fetched from Maven) and use it in a custom java_toolchain. Extending the default JavaBuilder requires knowledge of internal Bazel targets, private dependencies (like @io_bazel//third_party), and complex packaging/merging logic.
This proposal introduces a clean, public-facing Starlark API exposed under @bazel_tools//tools/jdk:javabuilder.bzl that allows clients to easily define custom JavaBuilder binaries and Error Prone check suites.
Proposed API Changes
We introduce two new public-facing rules/macros in @bazel_tools//tools/jdk:javabuilder.bzl:
default_javabuilder: A macro that packages a JavaBuilder executable. The default vanilla JavaBuilder is built by passing the default third-party Error Prone core libraries, while custom configurations can pass custom merged Error Prone engines.
errorprone_with_custom_plugins: A rule that merges a base Error Prone library (e.g. core Error Prone fetched from Maven) with custom checkers/plugins.
load("@bazel_tools//tools/jdk:javabuilder.bzl", "default_javabuilder", "errorprone_with_custom_plugins")
load("@rules_java//toolchains:default_java_toolchain.bzl", "DEFAULT_TOOLCHAIN_CONFIGURATION", "default_java_toolchain")
# 1. Merge core Error Prone with a custom pluginerrorprone_with_custom_plugins(
name="my_errorprone",
errorprone="@maven//:com_google_errorprone_error_prone_core",
plugins= [":my_plugin"],
)
# 2. Build the custom JavaBuilder deploy jardefault_javabuilder(
name="custom_javabuilder",
errorprone= [":my_errorprone"],
)
# 3. Associate it with a custom java_toolchaindefault_java_toolchain(
name="custom_toolchain",
configuration=DEFAULT_TOOLCHAIN_CONFIGURATION,
javabuilder=":custom_javabuilder_deploy.jar",
)
Note
Package-Level Configuration: Once a custom JavaBuilder is registered with the toolchain, users can configure the activation, severity, and options of these custom checkers on a package-by-package basis using the existing java_package_configuration API's javacopts attribute (e.g. passing "-Xep:CustomCheck:ERROR" for strict packages and "-Xep:CustomCheck:OFF" for legacy packages).
Implementation Overview & Expected Diffs
1. Bazel Core Diffs
API & Refactored JavaBuilder Targets (src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BUILD):
Description
Currently, there is no clean, public-facing API in Bazel or
@bazel_toolsto compile a customJavaBuilderbinary with extra Error Prone plugins/checkers (e.g., custom checks fetched from Maven) and use it in a customjava_toolchain. Extending the defaultJavaBuilderrequires knowledge of internal Bazel targets, private dependencies (like@io_bazel//third_party), and complex packaging/merging logic.This proposal introduces a clean, public-facing Starlark API exposed under
@bazel_tools//tools/jdk:javabuilder.bzlthat allows clients to easily define customJavaBuilderbinaries and Error Prone check suites.Proposed API Changes
We introduce two new public-facing rules/macros in
@bazel_tools//tools/jdk:javabuilder.bzl:default_javabuilder: A macro that packages aJavaBuilderexecutable. The default vanillaJavaBuilderis built by passing the default third-party Error Prone core libraries, while custom configurations can pass custom merged Error Prone engines.errorprone_with_custom_plugins: A rule that merges a base Error Prone library (e.g. core Error Prone fetched from Maven) with custom checkers/plugins.Note
Package-Level Configuration: Once a custom
JavaBuilderis registered with the toolchain, users can configure the activation, severity, and options of these custom checkers on a package-by-package basis using the existingjava_package_configurationAPI'sjavacoptsattribute (e.g. passing"-Xep:CustomCheck:ERROR"for strict packages and"-Xep:CustomCheck:OFF"for legacy packages).Implementation Overview & Expected Diffs
1. Bazel Core Diffs
src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BUILD):@bazel_tools(tools/BUILD):filegroup( name = "embedded_tools_srcs", srcs = [ ... + "//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:javabuilder_errorprone_api", + "//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:javabuilder_without_errorprone", ... ], )2.
rules_javaDiffsdefault_javabuilder(toolchains/default_java_toolchain.bzl):