From 1a2c184bfc9423ea236db869841291de3be2f0da Mon Sep 17 00:00:00 2001 From: David Sanderson <32687193+dws@users.noreply.github.com> Date: Thu, 12 Jun 2025 07:49:41 -0700 Subject: [PATCH 001/251] use DefaultInfo in rules_java (#303) We here address the following obstacles in `rules_java` to using Bazel's `--incompatible_disable_target_default_provider_fields` flag: ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: in java_toolchain rule @@rules_java+//toolchains:toolchain_jdk_21: Traceback (most recent call last): File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/java_toolchain.bzl", line 100, column 45, in _java_toolchain_impl jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None, Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details. ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: Analysis of target '@@rules_java+//toolchains:toolchain_jdk_21' failed ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: in java_import rule //third_party:netty_tcnative_checked_in: Traceback (most recent call last): File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/bazel/rules/bazel_java_import.bzl", line 25, column 34, in _proxy return bazel_java_import_rule( File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 132, column 35, in bazel_java_import_rule collected_jars = _collect_jars(ctx, jars) File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 38, column 24, in _collect_jars for jar in info.files.to_list(): Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details. ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: Analysis of target '//third_party:netty_tcnative_checked_in' failed ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed Closes #303 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/303 from dws:DefaultInfo c02b7724a5dcf85bb9c87bc06c1cd0504c0507f9 PiperOrigin-RevId: 770652076 Change-Id: Icc8a698ac66d76b47d9793a0c448d98d05e7186f --- .../common/rules/impl/bazel_java_import_impl.bzl | 4 ++-- java/common/rules/java_toolchain.bzl | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index 44656705..ce338cbd 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl @@ -35,7 +35,7 @@ def _collect_jars(ctx, jars): for info in jars: if JavaInfo in info: fail("'jars' attribute cannot contain labels of Java targets") - for jar in info.files.to_list(): + for jar in info[DefaultInfo].files.to_list(): jar_path = jar.dirname + jar.basename if jars_dict.get(jar_path) != None: fail("in jars attribute of java_import rule //" + ctx.label.package + ":" + ctx.attr.name + ": " + jar.basename + " is a duplicate") @@ -179,7 +179,7 @@ def bazel_java_import_rule( # TODO(kotlaja): Revise if collected_runtimes can be added into construct_defaultinfo directly. collected_runtimes = [] for runtime_dep in ctx.attr.runtime_deps: - collected_runtimes.extend(runtime_dep.files.to_list()) + collected_runtimes.extend(runtime_dep[DefaultInfo].files.to_list()) target["DefaultInfo"] = construct_defaultinfo( ctx, diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index 2e4fc67e..fe32fc36 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -96,13 +96,13 @@ def _java_toolchain_impl(ctx): oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist java_toolchain_info = _new_javatoolchaininfo( bootclasspath = bootclasspath_info.bootclasspath, - ijar = ctx.attr.ijar.files_to_run if ctx.attr.ijar else None, - jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None, + ijar = ctx.attr.ijar[DefaultInfo].files_to_run if ctx.attr.ijar else None, + jacocorunner = ctx.attr.jacocorunner[DefaultInfo].files_to_run if ctx.attr.jacocorunner else None, java_runtime = java_runtime, jvm_opt = depset(get_internal_java_common().expand_java_opts(ctx, "jvm_opts", tokenize = False, exec_paths = True)), label = ctx.label, - proguard_allowlister = ctx.attr.proguard_allowlister.files_to_run if ctx.attr.proguard_allowlister else None, - single_jar = ctx.attr.singlejar.files_to_run, + proguard_allowlister = ctx.attr.proguard_allowlister[DefaultInfo].files_to_run if ctx.attr.proguard_allowlister else None, + single_jar = ctx.attr.singlejar[DefaultInfo].files_to_run, source_version = ctx.attr.source_version, target_version = ctx.attr.target_version, tools = depset(ctx.files.tools), @@ -131,7 +131,7 @@ def _java_toolchain_impl(ctx): _javac_supports_worker_multiplex_sandboxing = ctx.attr.javac_supports_worker_multiplex_sandboxing, _jspecify_info = _get_jspecify_info(ctx), _local_java_optimization_config = ctx.files._local_java_optimization_configuration, - _one_version_tool = ctx.attr.oneversion.files_to_run if ctx.attr.oneversion else None, + _one_version_tool = ctx.attr.oneversion[DefaultInfo].files_to_run if ctx.attr.oneversion else None, _one_version_allowlist = oneversion_allowlist, _one_version_allowlist_for_tests = ctx.file.oneversion_allowlist_for_tests, _package_configuration = [dep[JavaPackageConfigurationInfo] for dep in ctx.attr.package_configuration], @@ -171,7 +171,7 @@ def _get_javac_opts(ctx): def _get_android_lint_tool(ctx): if not ctx.attr.android_lint_runner: return None - files_to_run = ctx.attr.android_lint_runner.files_to_run + files_to_run = ctx.attr.android_lint_runner[DefaultInfo].files_to_run if not files_to_run or not files_to_run.executable: fail(ctx.attr.android_lint_runner.label, "does not refer to a valid executable target") return struct( @@ -186,7 +186,7 @@ def _get_tool_from_ctx(ctx, tool_attr, data_attr, opts_attr): dep = getattr(ctx.attr, tool_attr) if not dep: return None - files_to_run = dep.files_to_run + files_to_run = dep[DefaultInfo].files_to_run if not files_to_run or not files_to_run.executable: fail(dep.label, "does not refer to a valid executable target") data = getattr(ctx.attr, data_attr) @@ -200,7 +200,7 @@ def _get_tool_from_executable(ctx, attr_name, data = [], jvm_opts = []): dep = getattr(ctx.attr, attr_name) if not dep: return None - files_to_run = dep.files_to_run + files_to_run = dep[DefaultInfo].files_to_run if not files_to_run or not files_to_run.executable: fail(dep.label, "does not refer to a valid executable target") return struct(tool = files_to_run, data = depset(data), jvm_opts = depset(jvm_opts)) From d927aa05abfda8bf3fb988ab77dc73d5f2a825f5 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 12 Jun 2025 09:46:53 -0700 Subject: [PATCH 002/251] Fix Runfiles docs after #301 (#302) Closes #302 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/302 from fmeum:patch-4 feca4dbff3d928b2165d31d82bbe6a9ff7803e6e PiperOrigin-RevId: 770694363 Change-Id: I3c369b638abbdd4c4fb9ad414802e4af1b5abfea --- .../java/com/google/devtools/build/runfiles/Runfiles.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/runfiles/src/main/java/com/google/devtools/build/runfiles/Runfiles.java b/java/runfiles/src/main/java/com/google/devtools/build/runfiles/Runfiles.java index 681f2479..06221b76 100644 --- a/java/runfiles/src/main/java/com/google/devtools/build/runfiles/Runfiles.java +++ b/java/runfiles/src/main/java/com/google/devtools/build/runfiles/Runfiles.java @@ -46,7 +46,7 @@ *

2. Import the runfiles library. * *

- *   import Runfiles;
+ *   import com.google.devtools.build.runfiles.Runfiles;
  * 
* *

3. Create a {@link Runfiles.Preloaded} object: @@ -64,7 +64,7 @@ * repository containing the class from a constant generated by this annotation: * *

- *   import AutoBazelRepository;
+ *   import com.google.devtools.build.runfiles.AutoBazelRepository;
  *   @AutoBazelRepository
  *   public class MyClass {
  *     public void myFunction() {

From c289c727a19935dc6292545ce101972e02a667fd Mon Sep 17 00:00:00 2001
From: Googler 
Date: Fri, 20 Jun 2025 02:11:50 -0700
Subject: [PATCH 003/251] Update `java_tools` `v15.0`

Built at: https://github.com/bazelbuild/bazel/commit/387ed020deff607abcebe9b82ba8ea61da5a5e9d

PiperOrigin-RevId: 773600616
Change-Id: I3c31ec7e0f174503053f242546331bd658dafdfb
---
 java/repositories.bzl | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/java/repositories.bzl b/java/repositories.bzl
index ee1d029a..548fb2a0 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -22,33 +22,33 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository")
 
 # visible for tests
 JAVA_TOOLS_CONFIG = {
-    "version": "v14.0",
+    "version": "v15.0",
     "release": "true",
     "artifacts": {
         "java_tools_linux": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v14.0/java_tools_linux-v14.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v14.0/java_tools_linux-v14.0.zip",
-            "sha": "51ed941d6c62e432e59cc3b6ad3503639cc138ee7a02ed6bf0bbbb16ded418c9",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_linux-v15.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_linux-v15.0.zip",
+            "sha": "8d9311ced79b7f346f7e71e924fbd9d3de0bb64c486c6e4cd27ea0287b4b9ab6",
         },
         "java_tools_windows": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v14.0/java_tools_windows-v14.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v14.0/java_tools_windows-v14.0.zip",
-            "sha": "3f918fb9c24b04bcd6088ed62c240cfbb1a4bb50376e394151d34d60e8e71cdf",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_windows-v15.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_windows-v15.0.zip",
+            "sha": "118691add8965116c716afc0eae2e0c079d39068c84e3d650c53b4ad18d27f10",
         },
         "java_tools_darwin_x86_64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v14.0/java_tools_darwin_x86_64-v14.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v14.0/java_tools_darwin_x86_64-v14.0.zip",
-            "sha": "94daf7d9586943261114de6bde97053597ce031bb8d76672688843b33b7ff610",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_darwin_x86_64-v15.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_darwin_x86_64-v15.0.zip",
+            "sha": "b06facc077b01314884ea5f7e4dbdff20a0541f547d2249401ebcc1d3ae329c1",
         },
         "java_tools_darwin_arm64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v14.0/java_tools_darwin_arm64-v14.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v14.0/java_tools_darwin_arm64-v14.0.zip",
-            "sha": "5f12ea12d0381058dac8aa85ad3656c3a7ab85b8c5d8cd98e4ab57bd8fbf8bee",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_darwin_arm64-v15.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_darwin_arm64-v15.0.zip",
+            "sha": "9c9d3b42576ccc6c2e908877b1576bdaa274d8db1bdf4b7c80d767e4b4185d6e",
         },
         "java_tools": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v14.0/java_tools-v14.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v14.0/java_tools-v14.0.zip",
-            "sha": "1c2074e3ffb8c5bd22d5e65964535f70ba7b1bcd4e688f5d89f79f72a1b625bf",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools-v15.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools-v15.0.zip",
+            "sha": "abae85fc87da0221cfaa8c1f11bce3db892c2b6946be7d9752cfa1e7fca36756",
         },
     },
 }

From d1e335a58dcc24ca386042d7d9891d71013650d5 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Fri, 20 Jun 2025 02:18:17 -0700
Subject: [PATCH 004/251] Release `rules_java` `v8.13.0`

PiperOrigin-RevId: 773602637
Change-Id: I14b501ee01214980a50cc56b645e2eecdb3d3266
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 9a1562e9..7f1e91ce 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.12.0",
+    version = "8.13.0",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From 3daed1aeb1baa4d8867119785d60b50be4aa8b40 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 24 Jun 2025 02:15:16 -0700
Subject: [PATCH 005/251] Update `@rules_java` CI to use Bazel `8.3.0`

PiperOrigin-RevId: 775136930
Change-Id: Iac7046b3c16682277bcc18fe3751d3fdce1271c4
---
 .bazelci/presubmit.yml | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 18088a21..3840395e 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -42,14 +42,12 @@ test_target_integration: &test_target_integration
 flags_workspace_integration: &flags_workspace_integration
   - "--noenable_bzlmod"
   - "--enable_workspace"
-  # TODO(hvd): remove after Bazel 8.3.0
-  - "--repositories_without_autoloads=bazel_features_version,bazel_features_globals"
 
 buildifier: latest
 
 matrix:
   all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
-  bazel: ["7.6.1", "8.2.1", "last_green"] # Bazel 6 tested separately, needs different flags
+  bazel: ["7.6.1", "8.3.0", "last_green"] # Bazel 6 tested separately, needs different flags
   modern_bazel: ["last_green"] # Fully supported Bazel versions
 
 tasks:
@@ -62,8 +60,8 @@ tasks:
     test_targets: *test_targets
 # Bazel 8.x
   build_and_test_bazel8:
-    name: "Bazel 8.2.1"
-    bazel: "8.2.1"
+    name: "Bazel 8.3.0"
+    bazel: "8.3.0"
     platform: ${{ all_platforms }}
     build_targets: *build_targets
     test_targets: *test_targets

From d3f34085e87d436e12e1df2fa2d018cba59d0e2b Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 25 Jun 2025 08:39:51 -0700
Subject: [PATCH 006/251] Make C++ toolchain explicitly not mandatory

Fixes: https://github.com/bazelbuild/rules_java/issues/305
PiperOrigin-RevId: 775703888
Change-Id: I709ccc8f29a09470aa3c4653ce9e1c413fafbbe4
---
 java/bazel/rules/bazel_java_binary.bzl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl
index cbbe0de8..da547226 100644
--- a/java/bazel/rules/bazel_java_binary.bzl
+++ b/java/bazel/rules/bazel_java_binary.bzl
@@ -317,7 +317,7 @@ def make_binary_rule(implementation, *, doc, attrs, executable = False, test = F
         test = test,
         fragments = ["cpp", "java"],
         provides = [JavaInfo],
-        toolchains = [semantics.JAVA_TOOLCHAIN] + use_cc_toolchain() + (
+        toolchains = [semantics.JAVA_TOOLCHAIN] + use_cc_toolchain(mandatory = False) + (
             [semantics.JAVA_RUNTIME_TOOLCHAIN] if executable or test else []
         ) + (
             [_LAUNCHER_MAKER_TOOLCHAIN] if bazel_features.rules._has_launcher_maker_toolchain else []
@@ -331,7 +331,7 @@ def make_binary_rule(implementation, *, doc, attrs, executable = False, test = F
             "unstrippeddeployjar": "%{name}_deploy.jar.unstripped",
         },
         exec_groups = {
-            "cpp_link": exec_group(toolchains = use_cc_toolchain()),
+            "cpp_link": exec_group(toolchains = use_cc_toolchain(mandatory = False)),
         },
         subrules = [android_lint_subrule],
     )

From aec334a90360d4a3213d70810199679f53fa663c Mon Sep 17 00:00:00 2001
From: Googler 
Date: Mon, 7 Jul 2025 02:09:10 -0700
Subject: [PATCH 007/251] Migrate from deprecated
 cc_linking_context.libraries_to_link to
 cc_linking_context.linker_inputs.libraries

Rename static_mode_params_for_dynamic_library_libs to libraries. Previously it was a misnomer.

This is a no-op change.

PiperOrigin-RevId: 780012470
Change-Id: I418fc15f5c971cb68b033068e02ad719967101d8
---
 test/java/testutil/cc_info_subject.bzl | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/test/java/testutil/cc_info_subject.bzl b/test/java/testutil/cc_info_subject.bzl
index c123c3d8..2d7dca12 100644
--- a/test/java/testutil/cc_info_subject.bzl
+++ b/test/java/testutil/cc_info_subject.bzl
@@ -21,12 +21,11 @@ def _new_cc_info_linking_context_subject(cc_info, meta):
     )
     public = struct(
         equals = lambda other: _cc_info_linking_context_equals(self.actual, other, self.meta),
-        libraries_to_link = lambda: _new_cc_info_libraries_to_link_subject(self.actual.libraries_to_link, self.meta.derive("libraries_to_link")),
-        static_mode_params_for_dynamic_library_libs = lambda: _new_static_mode_params_for_dynamic_library_libs_subject(self.actual, self.meta),
+        library_files = lambda: _new_library_files_subject(self.actual, self.meta),
     )
     return public
 
-def _new_static_mode_params_for_dynamic_library_libs_subject(linking_context, meta):
+def _new_library_files_subject(linking_context, meta):
     libs = []
     for input in linking_context.linker_inputs.to_list():
         for lib in input.libraries:
@@ -39,9 +38,9 @@ def _new_static_mode_params_for_dynamic_library_libs_subject(linking_context, me
             else:
                 libs.append(lib.dynamic_library)
 
-    return subjects.collection(
-        libs,
-        meta = meta.derive("static_mode_params_for_dynamic_library_libs"),
+    return subjects.depset_file(
+        depset(libs),
+        meta = meta.derive("library_files"),
     )
 
 def _cc_info_linking_context_equals(actual, expected, meta):

From 0b94d21938932eab2367fdca443b1f8a5196f7ae Mon Sep 17 00:00:00 2001
From: Yun Peng 
Date: Tue, 8 Jul 2025 02:58:57 -0700
Subject: [PATCH 008/251] Use root test_deps target from bazel_skylib (#306)

Fixing
```
$ bazel build //src/test/java/com/google/devtools/build/lib/query2/cquery:FilesOutputFormatterCallbackTest
...
ERROR: /private/var/tmp/_bazel_pcloudy/829441223e9fec5a5a2e3d1dd743fdf0/external/rules_java+/java/BUILD:78:10: in filegroup rule @@rules_java+//java:for_bazel_tests: Visibility error:
target '@@bazel_skylib+//lib:test_deps' is not visible from
target '@@rules_java+//java:for_bazel_tests'
Recommendation: modify the visibility declaration if you think the dependency is legitimate. For more info see https://bazel.build/concepts/visibility
```
after upgrading bazel_skylib which contains https://github.com/bazelbuild/bazel-skylib/pull/508

Closes #306

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/306 from bazelbuild:meteorcloudy-patch-1 a0df97cd25f9784da04f55ac037eee4ae0fa777c
PiperOrigin-RevId: 780484650
Change-Id: I1516310b78322eeb62d982a2e2a69d7ec756f925
---
 java/BUILD | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/BUILD b/java/BUILD
index 31621486..452c7654 100644
--- a/java/BUILD
+++ b/java/BUILD
@@ -88,7 +88,7 @@ filegroup(
         "//java/common:for_bazel_tests",
         "//java/private:for_bazel_tests",
         "//java/toolchains:for_bazel_tests",
-        "@bazel_skylib//lib:test_deps",
+        "@bazel_skylib//:test_deps",
     ],
     visibility = ["//visibility:public"],
 )

From 3b9ca9949516b1211d4626985c1755252241d559 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Thu, 17 Jul 2025 08:21:31 -0700
Subject: [PATCH 009/251] Update to `java_tools` `v16.0`

PiperOrigin-RevId: 784188539
Change-Id: Iddd537d5bedf8f82490e2f4959b753a4ec63e065
---
 java/repositories.bzl | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/java/repositories.bzl b/java/repositories.bzl
index 548fb2a0..2af22140 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -22,33 +22,33 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository")
 
 # visible for tests
 JAVA_TOOLS_CONFIG = {
-    "version": "v15.0",
+    "version": "v16.0",
     "release": "true",
     "artifacts": {
         "java_tools_linux": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_linux-v15.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_linux-v15.0.zip",
-            "sha": "8d9311ced79b7f346f7e71e924fbd9d3de0bb64c486c6e4cd27ea0287b4b9ab6",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_linux-v16.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_linux-v16.0.zip",
+            "sha": "7c360c60da9b9079e31f18de198f23a22555dfb7b6e91e3c6a7103127b1a8538",
         },
         "java_tools_windows": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_windows-v15.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_windows-v15.0.zip",
-            "sha": "118691add8965116c716afc0eae2e0c079d39068c84e3d650c53b4ad18d27f10",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_windows-v16.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_windows-v16.0.zip",
+            "sha": "b41faa85fceeb2f852e48d51d000d3bf4f29da86ee61d0fc8cca46d297bccf22",
         },
         "java_tools_darwin_x86_64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_darwin_x86_64-v15.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_darwin_x86_64-v15.0.zip",
-            "sha": "b06facc077b01314884ea5f7e4dbdff20a0541f547d2249401ebcc1d3ae329c1",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_darwin_x86_64-v16.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_darwin_x86_64-v16.0.zip",
+            "sha": "a41de64afb663bb4880af52b55886098241b9222ee8ec1a0f6258d006ba247fb",
         },
         "java_tools_darwin_arm64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools_darwin_arm64-v15.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools_darwin_arm64-v15.0.zip",
-            "sha": "9c9d3b42576ccc6c2e908877b1576bdaa274d8db1bdf4b7c80d767e4b4185d6e",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_darwin_arm64-v16.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_darwin_arm64-v16.0.zip",
+            "sha": "b79900dccca7c26fbae9a38c4da80987445e07194517ec53e169c45f1a88c7be",
         },
         "java_tools": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v15.0/java_tools-v15.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v15.0/java_tools-v15.0.zip",
-            "sha": "abae85fc87da0221cfaa8c1f11bce3db892c2b6946be7d9752cfa1e7fca36756",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools-v16.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools-v16.0.zip",
+            "sha": "d8b126078705e91677db67b05f7b25ad6fa8865949e2dd38ff85e0553bfb0be2",
         },
     },
 }

From 02f488deec4eaf8188d8433762554dcc4e6083f7 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Fri, 18 Jul 2025 02:18:26 -0700
Subject: [PATCH 010/251] Release `@rules_java` `v8.14.0`

(ignore-relnotes)

PiperOrigin-RevId: 784501450
Change-Id: Iaeb8e09987f9d23956d180ca29cf4ee42345f1af
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 7f1e91ce..bd4f2111 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.13.0",
+    version = "8.14.0",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From d8246a409519f9d551dd866a46278e394bd1b295 Mon Sep 17 00:00:00 2001
From: Donald Duo Zhao 
Date: Fri, 18 Jul 2025 16:58:04 -0700
Subject: [PATCH 011/251] Automatic code cleanup.

PiperOrigin-RevId: 784744315
Change-Id: Ia6c12564112645ff2161dbb04a5b6f6393445026
---
 java/java_single_jar.bzl | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/java/java_single_jar.bzl b/java/java_single_jar.bzl
index 6812fcff..48aa45c3 100644
--- a/java/java_single_jar.bzl
+++ b/java/java_single_jar.bzl
@@ -3,9 +3,9 @@
 load("//java/common:java_common.bzl", "java_common")
 load("//java/common:java_info.bzl", "JavaInfo")
 
-def _java_single_jar(ctx):
+def _single_jar_inputs(deps, deploy_env):
     transitive_inputs = []
-    for dep in ctx.attr.deps:
+    for dep in deps:
         if JavaInfo in dep:
             info = dep[JavaInfo]
             transitive_inputs.append(info.transitive_runtime_jars)
@@ -25,11 +25,15 @@ def _java_single_jar(ctx):
     if hasattr(java_common, "JavaRuntimeClasspathInfo"):
         deploy_env_jars = depset(transitive = [
             dep[java_common.JavaRuntimeClasspathInfo].runtime_classpath
-            for dep in ctx.attr.deploy_env
+            for dep in deploy_env
         ])
         excluded_jars = {jar: None for jar in deploy_env_jars.to_list()}
         if excluded_jars:
             inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars])
+    return inputs
+
+def _java_single_jar(ctx):
+    inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env)
 
     args = ctx.actions.args()
     args.add_all("--sources", inputs)

From bbb99fa1450e1a92eb79ae77c841b08af9403ed2 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 30 Jul 2025 02:00:19 -0700
Subject: [PATCH 012/251] rules_java: Rename CcInfo#transitive_native_libraries
 to _legacy_transitive_native_libraries

This is needed to convert CcInfo to Starlark without causing a major regression.

Mark the field as legacy, becuase we'll need to eventually clean it up.

PiperOrigin-RevId: 788808464
Change-Id: I86a21b4b16bd2953961b0f1e7bae2d4ac43e0712
---
 java/common/rules/impl/java_binary_impl.bzl |  5 ++++-
 java/private/java_info.bzl                  | 15 ++++++++++++---
 java/testutil.bzl                           |  2 ++
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl
index a41a125b..15ae89b7 100644
--- a/java/common/rules/impl/java_binary_impl.bzl
+++ b/java/common/rules/impl/java_binary_impl.bzl
@@ -154,7 +154,10 @@ def basic_java_binary(
         if JavaInfo in dep:
             native_libs_depsets.append(dep[JavaInfo].transitive_native_libraries)
         if CcInfo in dep:
-            native_libs_depsets.append(dep[CcInfo].transitive_native_libraries())
+            if hasattr(dep[CcInfo], "_legacy_transitive_native_libraries"):
+                native_libs_depsets.append(dep[CcInfo]._legacy_transitive_native_libraries)
+            else:
+                native_libs_depsets.append(dep[CcInfo].transitive_native_libraries())
     native_libs_dirs = collect_native_deps_dirs(depset(transitive = native_libs_depsets))
     if native_libs_dirs:
         prefix = "${JAVA_RUNFILES}/" + ctx.workspace_name + "/"
diff --git a/java/private/java_info.bzl b/java/private/java_info.bzl
index bf793c5a..65c6f2a1 100644
--- a/java/private/java_info.bzl
+++ b/java/private/java_info.bzl
@@ -178,7 +178,8 @@ def merge(
         cc_info = semantics.minimize_cc_info(cc_common.merge_cc_infos(cc_infos = [p.cc_link_params_info for p in providers]))
         result.update(
             cc_link_params_info = cc_info,
-            transitive_native_libraries = cc_info.transitive_native_libraries(),
+            transitive_native_libraries =
+                cc_info._legacy_transitive_native_libraries if hasattr(cc_info, "_legacy_transitive_native_libraries") else cc_info.transitive_native_libraries(),
         )
     else:
         result.update(
@@ -679,14 +680,22 @@ def _javainfo_init_base(
         cc_info = semantics.minimize_cc_info(cc_common.merge_cc_infos(cc_infos = transitive_cc_infos))
         result.update(
             cc_link_params_info = cc_info,
-            transitive_native_libraries = cc_info.transitive_native_libraries(),
+            transitive_native_libraries =
+                cc_info._legacy_transitive_native_libraries if hasattr(cc_info, "_legacy_transitive_native_libraries") else cc_info.transitive_native_libraries(),
         )
     else:
+        transitive_native_libraries = []
+        if native_libraries:
+            merged_cc_info = cc_common.merge_cc_infos(cc_infos = native_libraries)
+            if hasattr(merged_cc_info, "_legacy_transitive_native_libraries"):
+                transitive_native_libraries = [merged_cc_info._legacy_transitive_native_libraries]
+            else:
+                transitive_native_libraries = [merged_cc_info.transitive_native_libraries()]
         result.update(
             transitive_native_libraries = depset(
                 order = "topological",
                 transitive = [dep.transitive_native_libraries for dep in concatenated_deps.runtimedeps_exports_deps] +
-                             ([cc_common.merge_cc_infos(cc_infos = native_libraries).transitive_native_libraries()] if native_libraries else []),
+                             transitive_native_libraries,
             ),
         )
     return result, concatenated_deps
diff --git a/java/testutil.bzl b/java/testutil.bzl
index 6207583b..4063ea6f 100644
--- a/java/testutil.bzl
+++ b/java/testutil.bzl
@@ -5,6 +5,8 @@
 # TODO: consider eventually upstreaming to rules_cc
 
 def _cc_info_transitive_native_libraries(cc_info):
+    if hasattr(cc_info, "_legacy_transitive_native_libraries"):
+        return cc_info._legacy_transitive_native_libraries
     return cc_info.transitive_native_libraries()
 
 def _cc_library_to_link_static_library(library_to_link):

From c0462f09c1a6f7607d5d6b86ba291746fd003a86 Mon Sep 17 00:00:00 2001
From: "Ian (Hee) Cha" 
Date: Fri, 1 Aug 2025 00:51:19 -0700
Subject: [PATCH 013/251] Update rules_java to 8.15.0 (#309)

See https://github.com/bazelbuild/rules_java/issues/308 for reference.

Closes #309

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/309 from bazelbuild:iancha1992-8.15.0 6d270fca325bf30fc4c9ad72443374649cd8b838
PiperOrigin-RevId: 789650494
Change-Id: I2482eb988d2710d5ff72adcc45bb677e23d27398
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index bd4f2111..6fafb13d 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.14.0",
+    version = "8.15.0",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From 45061b38c54f4ee8e3038601c5d857154c7ae9db Mon Sep 17 00:00:00 2001
From: Krishna Magar 
Date: Thu, 7 Aug 2025 04:59:43 -0700
Subject: [PATCH 014/251] Fix Java coverage support on Windows by adding
 coverage_main_class to launch_info (#311)

### Summary

This PR enables Java code coverage to work properly on Windows by adding the `coverage_main_class` to the `launch_info` metadata in `bazel_java_binary.bzl`. Without this addition, Bazel fails to properly instrument and run Java binaries with coverage enabled on Windows platforms.

### Changes

- Added `coverage_main_class` to `launch_info` in `bazel_java_binary.bzl` to explicitly define the main class used during coverage runs.

### Motivation

- Before this fix, attempts to run Java coverage tests on Windows would not produce proper coverage output.
- This is a step toward resolving [bazelbuild/bazel#18839](https://github.com/bazelbuild/bazel/issues/18839).

Closes #311

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/311 from KrishnaM256:master 78942a24d9e34daa2ec9cecd8473dbfbb8c64059
PiperOrigin-RevId: 792108185
Change-Id: Ia29301538eaa3f7ca1195230abb32536dbe52e4f
---
 java/bazel/rules/bazel_java_binary.bzl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl
index da547226..1e4411e7 100644
--- a/java/bazel/rules/bazel_java_binary.bzl
+++ b/java/bazel/rules/bazel_java_binary.bzl
@@ -232,7 +232,7 @@ def _create_stub(ctx, java_attrs, launcher, executable, jvm_flags, main_class, c
         jvm_flags_for_launcher = []
         for flag in jvm_flags:
             jvm_flags_for_launcher.extend(ctx.tokenize(flag))
-        return _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, executable)
+        return _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, coverage_enabled, executable, coverage_main_class)
 
     if runfiles_enabled:
         prefix = "" if helper.is_absolute_target_platform_path(ctx, java_executable) else "${JAVA_RUNFILES}/"
@@ -277,13 +277,15 @@ def _format_classpath_entry(runfiles_enabled, workspace_prefix, file):
 
     return "$(rlocation " + paths.normalize(workspace_prefix + file.short_path) + ")"
 
-def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, executable):
+def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, coverage_enabled, executable, coverage_main_class):
     launch_info = ctx.actions.args().use_param_file("%s", use_always = True).set_param_file_format("multiline")
     launch_info.add("binary_type=Java")
     launch_info.add(ctx.workspace_name, format = "workspace_name=%s")
     launch_info.add("1" if runfiles_enabled else "0", format = "symlink_runfiles_enabled=%s")
     launch_info.add(java_executable, format = "java_bin_path=%s")
     launch_info.add(main_class, format = "java_start_class=%s")
+    if coverage_enabled:
+        launch_info.add(coverage_main_class, format = "jacoco_main_class=%s")
     launch_info.add_joined(classpath, map_each = _short_path, join_with = ";", format_joined = "classpath=%s", omit_if_empty = False)
     launch_info.add_joined(jvm_flags_for_launcher, join_with = "\t", format_joined = "jvm_flags=%s", omit_if_empty = False)
     launch_info.add(semantics.find_java_runtime_toolchain(ctx).java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe")

From 344df11f54627997e17b12dbbe2538293affa258 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Thu, 7 Aug 2025 07:19:13 -0700
Subject: [PATCH 015/251] Release `@rules_java` `v8.15.1`

Context: https://github.com/bazelbuild/rules_java/pull/311#issuecomment-3164152220

(ignore-relnotes)

PiperOrigin-RevId: 792147204
Change-Id: Ic881922527848bf51e785cf6d275eebcbe55ab7f
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 6fafb13d..b4b3f762 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.15.0",
+    version = "8.15.1",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From e22f29aa1ea4c90ce284845c01c0133ce9d6137d Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 12 Aug 2025 06:01:50 -0700
Subject: [PATCH 016/251] Break the `java_helper.bzl` -> `cc_helper.bzl` edge

PiperOrigin-RevId: 794075211
Change-Id: I7f774b2b3378760e726fabdb0fa79ccf8ab08ea0
---
 java/bazel/rules/bazel_java_binary.bzl      |  4 +--
 java/bazel/rules/bazel_java_test.bzl        |  4 +--
 java/common/rules/impl/BUILD                |  1 +
 java/common/rules/impl/java_binary_impl.bzl | 32 +++++++++++++++++++++
 java/common/rules/impl/java_helper.bzl      | 30 +------------------
 5 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl
index 1e4411e7..de25ab8f 100644
--- a/java/bazel/rules/bazel_java_binary.bzl
+++ b/java/bazel/rules/bazel_java_binary.bzl
@@ -24,12 +24,12 @@ load(
 load("//java/common/rules:java_binary.bzl", "BASIC_JAVA_BINARY_ATTRIBUTES")
 load("//java/common/rules:rule_util.bzl", "merge_attrs")
 load("//java/common/rules/impl:java_binary_deploy_jar.bzl", "create_deploy_archives")
-load("//java/common/rules/impl:java_binary_impl.bzl", "basic_java_binary")
+load("//java/common/rules/impl:java_binary_impl.bzl", "basic_java_binary", "binary_provider_helper")
 load("//java/common/rules/impl:java_helper.bzl", "helper")
 load("//java/private:java_info.bzl", "JavaInfo")
 
 def _bazel_java_binary_impl(ctx):
-    return bazel_base_binary_impl(ctx, is_test_rule_class = False) + helper.executable_providers(ctx)
+    return bazel_base_binary_impl(ctx, is_test_rule_class = False) + binary_provider_helper.executable_providers(ctx)
 
 def bazel_base_binary_impl(ctx, is_test_rule_class):
     """Common implementation for binaries and tests
diff --git a/java/bazel/rules/bazel_java_test.bzl b/java/bazel/rules/bazel_java_test.bzl
index fd3e2bd2..061c058e 100644
--- a/java/bazel/rules/bazel_java_test.bzl
+++ b/java/bazel/rules/bazel_java_test.bzl
@@ -16,11 +16,11 @@
 load("//java/common:java_semantics.bzl", "semantics")
 load("//java/common/rules:java_binary.bzl", "BASE_TEST_ATTRIBUTES")
 load("//java/common/rules:rule_util.bzl", "merge_attrs")
-load("//java/common/rules/impl:java_helper.bzl", "helper")
+load("//java/common/rules/impl:java_binary_impl.bzl", "binary_provider_helper")
 load(":bazel_java_binary.bzl", "BASE_BINARY_ATTRS", "bazel_base_binary_impl", "make_binary_rule")
 
 def _bazel_java_test_impl(ctx):
-    return bazel_base_binary_impl(ctx, is_test_rule_class = True) + helper.test_providers(ctx)
+    return bazel_base_binary_impl(ctx, is_test_rule_class = True) + binary_provider_helper.test_providers(ctx)
 
 def _java_test_initializer(**kwargs):
     if "stamp" in kwargs and type(kwargs["stamp"]) == type(True):
diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD
index 65c5af86..aead3739 100644
--- a/java/common/rules/impl/BUILD
+++ b/java/common/rules/impl/BUILD
@@ -22,6 +22,7 @@ bzl_library(
         ":java_helper_bzl",
         "//java/common:proguard_spec_info_bzl",
         "@com_google_protobuf//bazel/common:proto_info_bzl",
+        "@rules_cc//cc/common:cc_helper_bzl",
     ],
 )
 
diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl
index 15ae89b7..50dcaae9 100644
--- a/java/common/rules/impl/java_binary_impl.bzl
+++ b/java/common/rules/impl/java_binary_impl.bzl
@@ -16,6 +16,7 @@
 
 load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
 load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
+load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper")
 load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
 load("//java/common:java_semantics.bzl", "semantics")
 load("//java/common/rules/impl:basic_java_library_impl.bzl", "basic_java_library", "collect_deps")
@@ -468,3 +469,34 @@ def _auto_create_deploy_jar(ctx, info, launcher_info, main_class, coverage_main_
         add_opens = info.add_opens,
     )
     return output
+
+def _test_providers(ctx):
+    test_providers = []
+    if helper.has_target_constraints(ctx, ctx.attr._apple_constraints):
+        test_providers.append(testing.ExecutionInfo({"requires-darwin": ""}))
+
+    test_env = {}
+    test_env.update(cc_helper.get_expanded_env(ctx, {}))
+
+    coverage_config = helper.get_coverage_config(
+        ctx,
+        runner = None,  # we only need the environment
+    )
+    if coverage_config:
+        test_env.update(coverage_config.env)
+    test_providers.append(testing.TestEnvironment(
+        environment = test_env,
+        inherited_environment = ctx.attr.env_inherit,
+    ))
+
+    return test_providers
+
+def _executable_providers(ctx):
+    if ctx.attr.create_executable:
+        return [RunEnvironmentInfo(cc_helper.get_expanded_env(ctx, {}))]
+    return []
+
+binary_provider_helper = struct(
+    executable_providers = _executable_providers,
+    test_providers = _test_providers,
+)
diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl
index c97d0060..683bf609 100644
--- a/java/common/rules/impl/java_helper.bzl
+++ b/java/common/rules/impl/java_helper.bzl
@@ -17,7 +17,6 @@
 load("@bazel_skylib//lib:paths.bzl", "paths")
 load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
 load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
-load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper")
 load("//java/common:java_semantics.bzl", "semantics")
 
 # copybara: rules_java visibility
@@ -278,32 +277,6 @@ def _get_test_support(ctx):
         return ctx.attr._test_support
     return None
 
-def _test_providers(ctx):
-    test_providers = []
-    if _has_target_constraints(ctx, ctx.attr._apple_constraints):
-        test_providers.append(testing.ExecutionInfo({"requires-darwin": ""}))
-
-    test_env = {}
-    test_env.update(cc_helper.get_expanded_env(ctx, {}))
-
-    coverage_config = _get_coverage_config(
-        ctx,
-        runner = None,  # we only need the environment
-    )
-    if coverage_config:
-        test_env.update(coverage_config.env)
-    test_providers.append(testing.TestEnvironment(
-        environment = test_env,
-        inherited_environment = ctx.attr.env_inherit,
-    ))
-
-    return test_providers
-
-def _executable_providers(ctx):
-    if ctx.attr.create_executable:
-        return [RunEnvironmentInfo(cc_helper.get_expanded_env(ctx, {}))]
-    return []
-
 def _resource_mapper(file):
     root_relative_path = paths.relativize(
         path = file.path,
@@ -499,8 +472,6 @@ helper = struct(
     is_target_platform_windows = _is_target_platform_windows,
     runfiles_enabled = _runfiles_enabled,
     get_test_support = _get_test_support,
-    test_providers = _test_providers,
-    executable_providers = _executable_providers,
     create_single_jar = _create_single_jar,
     shell_escape = _shell_escape,
     detokenize_javacopts = _detokenize_javacopts,
@@ -508,4 +479,5 @@ helper = struct(
     derive_output_file = _derive_output_file,
     is_stamping_enabled = _is_stamping_enabled,
     get_relative = _get_relative,
+    has_target_constraints = _has_target_constraints,
 )

From 52aa53a7b7e56a4e545fbda2323db181d3c8ee3d Mon Sep 17 00:00:00 2001
From: hvadehra 
Date: Tue, 19 Aug 2025 01:05:45 -0700
Subject: [PATCH 017/251] Add a module extension for registering local/remote
 jdks (#312)

Closes #312

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/312 from bazelbuild:hvd_java_repos_module_ext d11e12e2eda5b3cfb5e1075d03f095ef5ebe3871
PiperOrigin-RevId: 796756819
Change-Id: I7d672490bcb47e64c6dbb2f5138d261bee9fa52d
---
 java/extensions.bzl       |  3 ++
 test/repo/BUILD.bazel     |  5 ++++
 test/repo/MODULE.bazel    | 19 +++++++++++++
 test/repo/WORKSPACE       | 18 ++++++++++++
 toolchains/extensions.bzl | 59 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 104 insertions(+)
 create mode 100644 toolchains/extensions.bzl

diff --git a/java/extensions.bzl b/java/extensions.bzl
index f456f3f5..ad7978b6 100644
--- a/java/extensions.bzl
+++ b/java/extensions.bzl
@@ -23,6 +23,7 @@ load(
     "remote_jdk21_repos",
     "remote_jdk8_repos",
 )
+load("//toolchains:extensions.bzl", _java_repository = "java_repository")
 
 def _toolchains_impl(module_ctx):
     java_tools_repos()
@@ -38,3 +39,5 @@ def _toolchains_impl(module_ctx):
         return None
 
 toolchains = module_extension(_toolchains_impl)
+
+java_repository = _java_repository
diff --git a/test/repo/BUILD.bazel b/test/repo/BUILD.bazel
index ca414395..b0fb6122 100644
--- a/test/repo/BUILD.bazel
+++ b/test/repo/BUILD.bazel
@@ -53,4 +53,9 @@ default_java_toolchain(
     name = "my_funky_toolchain",
     bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath"],
     configuration = NONPREBUILT_TOOLCHAIN_CONFIGURATION,
+    exec_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    java_runtime = "@my_funky_jdk//:jdk",
 )
diff --git a/test/repo/MODULE.bazel b/test/repo/MODULE.bazel
index 1faec90d..62109333 100644
--- a/test/repo/MODULE.bazel
+++ b/test/repo/MODULE.bazel
@@ -49,6 +49,25 @@ use_repo(
     "remotejdk21_win",
 )
 
+custom_jdk = use_extension("@rules_java//java:extensions.bzl", "java_repository")
+custom_jdk.remote(
+    name = "my_funky_jdk",
+    prefix = "funky",
+    strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64",
+    target_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    urls = [
+        "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz",
+    ],
+    version = "24",
+)
+use_repo(custom_jdk, "my_funky_jdk", "my_funky_jdk_toolchain_config_repo")
+
+register_toolchains("@my_funky_jdk_toolchain_config_repo//:all")
+
 register_toolchains("//:all")
 
 bazel_dep(name = "rules_shell", version = "0.4.0", dev_dependency = True)
+bazel_dep(name = "platforms", version = "0.0.11", dev_dependency = True)
diff --git a/test/repo/WORKSPACE b/test/repo/WORKSPACE
index c272975e..a6055e26 100644
--- a/test/repo/WORKSPACE
+++ b/test/repo/WORKSPACE
@@ -47,3 +47,21 @@ load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_
 rules_shell_dependencies()
 
 rules_shell_toolchains()
+
+load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_repository")
+
+remote_java_repository(
+    name = "my_funky_jdk",
+    prefix = "funky",
+    strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64",
+    target_compatible_with = [
+        "@platforms//os:linux",
+        "@platforms//cpu:x86_64",
+    ],
+    urls = [
+        "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz",
+    ],
+    version = "24",
+)
+
+register_toolchains("@my_funky_jdk_toolchain_config_repo//:all")
diff --git a/toolchains/extensions.bzl b/toolchains/extensions.bzl
new file mode 100644
index 00000000..330c7070
--- /dev/null
+++ b/toolchains/extensions.bzl
@@ -0,0 +1,59 @@
+"""Module extensions for local and remote java repositories"""
+
+load(":local_java_repository.bzl", "local_java_repository")
+load(":remote_java_repository.bzl", "remote_java_repository")
+
+visibility(["//java"])
+
+def _java_repository_impl(mctx):
+    for mod in mctx.modules:
+        if not mod.is_root:
+            fail(
+                """This module extension may only be used in the root module. {name}
+                must set `dev_dependency` = True on it's usage of this extension,
+                if {name} can be dependency of other modules.""".format(name = mod.name),
+            )
+        for local in mod.tags.local:
+            local_java_repository(
+                local.name,
+                java_home = local.java_home,
+                version = local.version,
+                build_file = local.build_file,
+                build_file_content = local.build_file_content,
+            )
+        for remote in mod.tags.remote:
+            remote_java_repository(
+                remote.name,
+                remote.version,
+                target_compatible_with = remote.target_compatible_with,
+                prefix = remote.prefix,
+                sha256 = remote.sha256,
+                strip_prefix = remote.strip_prefix,
+                urls = remote.urls,
+            )
+
+_local = tag_class(attrs = {
+    "name": attr.string(mandatory = True),
+    "build_file": attr.label(default = None),
+    "build_file_content": attr.string(default = ""),
+    "java_home": attr.string(default = ""),
+    "version": attr.string(default = ""),
+})
+
+_remote = tag_class(attrs = {
+    "name": attr.string(mandatory = True),
+    "version": attr.string(mandatory = True),
+    "urls": attr.string_list(mandatory = True),
+    "prefix": attr.string(default = ""),
+    "sha256": attr.string(default = ""),
+    "strip_prefix": attr.string(default = ""),
+    "target_compatible_with": attr.string_list(default = []),
+})
+
+java_repository = module_extension(
+    _java_repository_impl,
+    tag_classes = {
+        "local": _local,
+        "remote": _remote,
+    },
+)

From d8744976967245dfab3f6575a64a8d1c21c926b8 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Mon, 1 Sep 2025 06:03:11 -0700
Subject: [PATCH 018/251] Release `rules_java` `v8.15.2`

(ignore-relnotes)

PiperOrigin-RevId: 801782248
Change-Id: I3b005be33e07803e4e6c92b40bb265b0f1223e2c
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index b4b3f762..e4211f31 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.15.1",
+    version = "8.15.2",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From 4bd56d5d62c7d9a630928c704262dc0a87614829 Mon Sep 17 00:00:00 2001
From: Honnix 
Date: Tue, 2 Sep 2025 04:11:54 -0700
Subject: [PATCH 019/251] chore: Support remote_file_urls and
 remote_file_integrity in extension (#315)

Closes #314

Closes #315

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/315 from honnix:honnix/remote-file a0c276db08d7268781a3c17b5af6b9fd7f03b741
PiperOrigin-RevId: 802081702
Change-Id: I7bd2b082933844eed24570553fdb2fc20f51777c
---
 toolchains/extensions.bzl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/toolchains/extensions.bzl b/toolchains/extensions.bzl
index 330c7070..1db0cbc9 100644
--- a/toolchains/extensions.bzl
+++ b/toolchains/extensions.bzl
@@ -27,6 +27,8 @@ def _java_repository_impl(mctx):
                 remote.version,
                 target_compatible_with = remote.target_compatible_with,
                 prefix = remote.prefix,
+                remote_file_urls = remote.remote_file_urls,
+                remote_file_integrity = remote.remote_file_integrity,
                 sha256 = remote.sha256,
                 strip_prefix = remote.strip_prefix,
                 urls = remote.urls,
@@ -45,6 +47,8 @@ _remote = tag_class(attrs = {
     "version": attr.string(mandatory = True),
     "urls": attr.string_list(mandatory = True),
     "prefix": attr.string(default = ""),
+    "remote_file_urls": attr.string_list_dict(default = {}),
+    "remote_file_integrity": attr.string_dict(default = {}),
     "sha256": attr.string(default = ""),
     "strip_prefix": attr.string(default = ""),
     "target_compatible_with": attr.string_list(default = []),

From 79073396241f383d012572c7e110b6cabe755a84 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Mon, 8 Sep 2025 01:12:44 -0700
Subject: [PATCH 020/251] Update `rules_java` CI to use Bazel 8.4.0

(ignore-relnotes)

PiperOrigin-RevId: 804312769
Change-Id: Ib4a59f43e449d12d60f1509e1134e3a3c524f0b4
---
 .bazelci/presubmit.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 3840395e..796212bf 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -47,7 +47,7 @@ buildifier: latest
 
 matrix:
   all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
-  bazel: ["7.6.1", "8.3.0", "last_green"] # Bazel 6 tested separately, needs different flags
+  bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags
   modern_bazel: ["last_green"] # Fully supported Bazel versions
 
 tasks:
@@ -60,8 +60,8 @@ tasks:
     test_targets: *test_targets
 # Bazel 8.x
   build_and_test_bazel8:
-    name: "Bazel 8.3.0"
-    bazel: "8.3.0"
+    name: "Bazel 8.4.0"
+    bazel: "8.4.0"
     platform: ${{ all_platforms }}
     build_targets: *build_targets
     test_targets: *test_targets

From 6f74e94b5df3d8de190e6bcd3750f95e278ab3ef Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 10 Sep 2025 06:18:50 -0700
Subject: [PATCH 021/251] Run `@rules_java` CI on rolling Bazel releases

(ignore-relnotes)

PiperOrigin-RevId: 805331268
Change-Id: I785f5568e335aabb5896a01520dab9c83874c56b
---
 .bazelci/presubmit.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 796212bf..7357c253 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -48,7 +48,7 @@ buildifier: latest
 matrix:
   all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
   bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags
-  modern_bazel: ["last_green"] # Fully supported Bazel versions
+  modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions
 
 tasks:
 # Bazel 9+

From faaab4062f81deefaeef76dd21b2a5212432f8e3 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Thu, 11 Sep 2025 05:46:41 -0700
Subject: [PATCH 022/251] Use `@bazel_features` for rules_java compatibility
 proxy

The previous check would have eventually broken with Bazel 10.

PiperOrigin-RevId: 805798844
Change-Id: I4ea5d594f0e370d7d3b7568d54626944fe8f1923
---
 WORKSPACE                | 13 ++++++++++---
 distro/relnotes.bzl      | 11 +++++++++--
 java/rules_java_deps.bzl | 15 ++-------------
 test/repo/WORKSPACE      | 15 +++++++++++----
 4 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/WORKSPACE b/WORKSPACE
index acd7cae0..475e9ef8 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -37,14 +37,21 @@ http_archive(
     ],
 )
 
-load("//java:rules_java_deps.bzl", "rules_java_dependencies")
-
-rules_java_dependencies()
+http_archive(
+    name = "bazel_features",
+    sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b",
+    strip_prefix = "bazel_features-1.30.0",
+    url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz",
+)
 
 load("@bazel_features//:deps.bzl", "bazel_features_deps")
 
 bazel_features_deps()
 
+load("//java:rules_java_deps.bzl", "rules_java_dependencies")
+
+rules_java_dependencies()
+
 load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features")  # buildifier: disable=bzl-visibility
 
 proto_bazel_features(name = "proto_bazel_features")
diff --git a/distro/relnotes.bzl b/distro/relnotes.bzl
index ce04d501..9d76230a 100644
--- a/distro/relnotes.bzl
+++ b/distro/relnotes.bzl
@@ -38,12 +38,19 @@ http_archive(
     sha256 = "$$sha",
 )
 
-load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
-rules_java_dependencies()
+http_archive(
+    name = "bazel_features",
+    sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b",
+    strip_prefix = "bazel_features-1.30.0",
+    url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz",
+)
 
 load("@bazel_features//:deps.bzl", "bazel_features_deps")
 bazel_features_deps()
 
+load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
+rules_java_dependencies()
+
 # note that the following line is what is minimally required from protobuf for the java rules
 # consider using the protobuf_deps() public API from @com_google_protobuf//:protobuf_deps.bzl
 load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features")  # buildifier: disable=bzl-visibility
diff --git a/java/rules_java_deps.bzl b/java/rules_java_deps.bzl
index b32edd24..1eb28492 100644
--- a/java/rules_java_deps.bzl
+++ b/java/rules_java_deps.bzl
@@ -1,12 +1,11 @@
 """Module extension for compatibility with previous Bazel versions"""
 
+load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge")
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
 
 def _compatibility_proxy_repo_impl(rctx):
-    # TODO: use @bazel_features
-    bazel = native.bazel_version
-    if not bazel or bazel >= "8":
+    if _bazel_version_ge("8.0.0"):
         rctx.file(
             "BUILD.bazel",
             """
@@ -210,15 +209,6 @@ def rules_license_repo():
         ],
     )
 
-def bazel_features_repo():
-    maybe(
-        http_archive,
-        name = "bazel_features",
-        sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b",
-        strip_prefix = "bazel_features-1.30.0",
-        url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz",
-    )
-
 def rules_java_dependencies():
     """An utility method to load non-toolchain dependencies of rules_java.
 
@@ -232,4 +222,3 @@ def rules_java_dependencies():
     zlib_repo()
     absl_repo()
     rules_license_repo()
-    bazel_features_repo()
diff --git a/test/repo/WORKSPACE b/test/repo/WORKSPACE
index a6055e26..32cadb59 100644
--- a/test/repo/WORKSPACE
+++ b/test/repo/WORKSPACE
@@ -5,14 +5,23 @@ local_repository(
     path = "../../",
 )
 
-load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 
-rules_java_dependencies()
+http_archive(
+    name = "bazel_features",
+    sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b",
+    strip_prefix = "bazel_features-1.30.0",
+    url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz",
+)
 
 load("@bazel_features//:deps.bzl", "bazel_features_deps")
 
 bazel_features_deps()
 
+load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
+
+rules_java_dependencies()
+
 load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features")  # buildifier: disable=bzl-visibility
 
 proto_bazel_features(name = "proto_bazel_features")
@@ -33,8 +42,6 @@ http_jar(
     ],
 )
 
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
 http_archive(
     name = "rules_shell",
     sha256 = "3e114424a5c7e4fd43e0133cc6ecdfe54e45ae8affa14fadd839f29901424043",

From 0423b071e1b183b55f35a0af02d9cd578e88b9e8 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Mon, 22 Sep 2025 07:49:34 -0700
Subject: [PATCH 023/251] Fix CI failures with last_green (#321)

Closes #321

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/321 from fmeum:patch-3 bfde788dea60116dce574168a5c7cec98f5395ae
PiperOrigin-RevId: 810011421
Change-Id: I7d91fa12565fe856de8dbfcefb8f640fb6814f24
---
 MODULE.bazel                               |  29 +++-
 third_party/BUILD                          |   0
 third_party/abseil-cpp_load-cc-rules.patch |  36 +++++
 third_party/protobuf_load-cc-rules.patch   | 157 +++++++++++++++++++++
 4 files changed, 217 insertions(+), 5 deletions(-)
 create mode 100644 third_party/BUILD
 create mode 100644 third_party/abseil-cpp_load-cc-rules.patch
 create mode 100644 third_party/protobuf_load-cc-rules.patch

diff --git a/MODULE.bazel b/MODULE.bazel
index e4211f31..942c1bb2 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -6,15 +6,34 @@ module(
 )
 
 bazel_dep(name = "platforms", version = "0.0.11")
-bazel_dep(name = "rules_cc", version = "0.0.15")
+bazel_dep(name = "rules_cc", version = "0.2.8")
 bazel_dep(name = "bazel_features", version = "1.30.0")
 bazel_dep(name = "bazel_skylib", version = "1.6.1")
-bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
+bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf")
 bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
 
 # Required by @remote_java_tools, which is loaded via module extension.
 bazel_dep(name = "rules_license", version = "0.0.3")
-bazel_dep(name = "abseil-cpp", version = "20230802.1", repo_name = "com_google_absl")
+bazel_dep(name = "abseil-cpp", version = "20250814.0", repo_name = "com_google_absl")
+
+# TODO: Remove this override after the next release of abseil-cpp.
+single_version_override(
+    module_name = "abseil-cpp",
+    patch_strip = 1,
+    patches = [
+        "//third_party:abseil-cpp_load-cc-rules.patch",
+    ],
+    version = "20250814.0",
+)
+
+single_version_override(
+    module_name = "protobuf",
+    patch_strip = 1,
+    patches = [
+        "//third_party:protobuf_load-cc-rules.patch",
+    ],
+    version = "32.1",
+)
 
 register_toolchains("//toolchains:all")
 
@@ -97,9 +116,9 @@ use_repo(compat, "compatibility_proxy")
 
 # Dev dependencies
 bazel_dep(name = "rules_pkg", version = "0.9.1", dev_dependency = True)
-bazel_dep(name = "stardoc", version = "0.7.1", dev_dependency = True)
+bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True)
 bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True)
-bazel_dep(name = "rules_testing", version = "0.7.0", dev_dependency = True)
+bazel_dep(name = "rules_testing", dev_dependency = True)
 archive_override(
     module_name = "rules_testing",
     integrity = "sha256-0+3pLjeZCqn+K1qS7HNr7HbwMXBjxLvJm+pMSUhDel8=",
diff --git a/third_party/BUILD b/third_party/BUILD
new file mode 100644
index 00000000..e69de29b
diff --git a/third_party/abseil-cpp_load-cc-rules.patch b/third_party/abseil-cpp_load-cc-rules.patch
new file mode 100644
index 00000000..e3dfe2bb
--- /dev/null
+++ b/third_party/abseil-cpp_load-cc-rules.patch
@@ -0,0 +1,36 @@
+From 2370ccf579bd0fb4484c343389b8121c6b7f9bb8 Mon Sep 17 00:00:00 2001
+From: Keith Smiley 
+Date: Sat, 20 Sep 2025 20:02:06 -0700
+Subject: [PATCH] PR #1939: Add missing rules_cc loads
+
+Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1939
+
+This is required for use with bazel past this commit: https://github.com/bazelbuild/bazel/commit/71ca0ed111ff3d842a0d23bc3a46bd2e6745491d
+
+Most files do this already these were just missing
+
+Merge f7d58947afdb0549c9e5c287a5e5851a7d72e1e0 into 620d600442769b7ec4b61bd87667899908eec4ef
+
+Merging this change closes #1939
+
+COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1939 from keith:ks/add-missing-rules_cc-loads f7d58947afdb0549c9e5c287a5e5851a7d72e1e0
+PiperOrigin-RevId: 809556509
+Change-Id: I494a118b851685a03393485514a3b6fbe3a10597
+---
+ absl/debugging/BUILD.bazel | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel
+index ed7cc493e90..7cc053e783e 100644
+--- a/absl/debugging/BUILD.bazel
++++ b/absl/debugging/BUILD.bazel
+@@ -14,6 +14,9 @@
+ # limitations under the License.
+ #
+ 
++load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
++load("@rules_cc//cc:cc_test.bzl", "cc_test")
+ load(
+     "//absl:copts/configure_copts.bzl",
+     "ABSL_DEFAULT_COPTS",
diff --git a/third_party/protobuf_load-cc-rules.patch b/third_party/protobuf_load-cc-rules.patch
new file mode 100644
index 00000000..09bd7025
--- /dev/null
+++ b/third_party/protobuf_load-cc-rules.patch
@@ -0,0 +1,157 @@
+Backported from https://github.com/protocolbuffers/protobuf/pull/23584 to 32.0:
+
+From 733a0ccf6f53f469352b19440a1d152eccea6bec Mon Sep 17 00:00:00 2001
+From: Keith Smiley 
+Date: Sat, 20 Sep 2025 09:30:37 -0700
+Subject: [PATCH] bazel: add missing rules_cc loads
+
+This is required for use with bazel after this commit https://github.com/bazelbuild/bazel/commit/71ca0ed111ff3d842a0d23bc3a46bd2e6745491d
+
+Many files have these already
+---
+ lua/BUILD.bazel                                    | 3 +++
+ pkg/test/BUILD.bazel                               | 1 +
+ ruby/ext/google/protobuf_c/BUILD.bazel             | 1 +
+ ruby/lib/google/BUILD.bazel                        | 1 +
+ rust/defs.bzl                                      | 1 +
+ src/google/protobuf/compiler/cpp/BUILD.bazel       | 1 +
+ src/google/protobuf/compiler/java/full/BUILD.bazel | 1 +
+ src/google/protobuf/compiler/java/lite/BUILD.bazel | 1 +
+ src/google/protobuf/compiler/kotlin/BUILD.bazel    | 1 +
+ src/google/protobuf/compiler/php/BUILD.bazel       | 1 +
+ src/google/protobuf/compiler/rust/BUILD.bazel      | 2 ++
+ toolchain/BUILD.bazel                              | 2 ++
+ 12 files changed, 16 insertions(+)
+
+diff --git a/lua/BUILD.bazel b/lua/BUILD.bazel
+index 389e5da7635ca..db956713bd849 100644
+--- a/lua/BUILD.bazel
++++ b/lua/BUILD.bazel
+@@ -5,6 +5,9 @@
+ # license that can be found in the LICENSE file or at
+ # https://developers.google.com/open-source/licenses/bsd
+ 
++load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
++load("@rules_cc//cc:cc_test.bzl", "cc_test")
+ load("//bazel:proto_library.bzl", "proto_library")
+ load(
+     "//lua:lua_proto_library.bzl",
+diff --git a/pkg/test/BUILD.bazel b/pkg/test/BUILD.bazel
+index d0954f0126ba2..4fd01c9759643 100644
+--- a/pkg/test/BUILD.bazel
++++ b/pkg/test/BUILD.bazel
+@@ -1,5 +1,6 @@
+ # Tests for CMake file list generation
+ 
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
+ load("@rules_shell//shell:sh_test.bzl", "sh_test")
+ load("//pkg:build_systems.bzl", "gen_file_lists")
+ load("//pkg:cc_dist_library.bzl", "cc_dist_library")
+diff --git a/ruby/ext/google/protobuf_c/BUILD.bazel b/ruby/ext/google/protobuf_c/BUILD.bazel
+index 00458e2eedbe4..63276d538cc5c 100644
+--- a/ruby/ext/google/protobuf_c/BUILD.bazel
++++ b/ruby/ext/google/protobuf_c/BUILD.bazel
+@@ -1,4 +1,5 @@
+ load("@build_bazel_rules_apple//apple:apple_binary.bzl", "apple_binary")
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
+ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+ load("//upb/cmake:build_defs.bzl", "staleness_test")
+ 
+diff --git a/ruby/lib/google/BUILD.bazel b/ruby/lib/google/BUILD.bazel
+index db0d7cd6b89bc..157df81b6d734 100644
+--- a/ruby/lib/google/BUILD.bazel
++++ b/ruby/lib/google/BUILD.bazel
+@@ -1,3 +1,4 @@
++load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
+ load("@rules_java//java:java_binary.bzl", "java_binary")
+ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+ load("@rules_ruby//ruby:defs.bzl", "rb_library")
+diff --git a/rust/defs.bzl b/rust/defs.bzl
+index b787d108fc743..54dab26e25048 100644
+--- a/rust/defs.bzl
++++ b/rust/defs.bzl
+@@ -1,4 +1,5 @@
+ """This file implements rust_proto_library."""
+ 
++load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
+ load("@rules_rust//rust:defs.bzl", "rust_common")
+ load("//bazel/common:proto_common.bzl", "proto_common")
+diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel
+index 4d4e99d774772..ced92c04e235d 100644
+--- a/src/google/protobuf/compiler/cpp/BUILD.bazel
++++ b/src/google/protobuf/compiler/cpp/BUILD.bazel
+@@ -2,6 +2,7 @@
+ # Protocol Buffers Compiler - C++ code generator
+ ################################################################################
+ 
++load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
+ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
+ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+ load("//bazel:cc_proto_library.bzl", "cc_proto_library")
+diff --git a/src/google/protobuf/compiler/java/full/BUILD.bazel b/src/google/protobuf/compiler/java/full/BUILD.bazel
+index 6bffaa10fbc87..54b4ae9cd186d 100644
+--- a/src/google/protobuf/compiler/java/full/BUILD.bazel
++++ b/src/google/protobuf/compiler/java/full/BUILD.bazel
+@@ -1,6 +1,7 @@
+ # We use abbreviated target names in this directory to work around:
+ #     https://github.com/bazelbuild/bazel/issues/18683
+ 
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
+ load("//build_defs:cpp_opts.bzl", "COPTS")
+ 
+ cc_library(
+diff --git a/src/google/protobuf/compiler/java/lite/BUILD.bazel b/src/google/protobuf/compiler/java/lite/BUILD.bazel
+index 02af1b3f917df..5e04135abbac0 100644
+--- a/src/google/protobuf/compiler/java/lite/BUILD.bazel
++++ b/src/google/protobuf/compiler/java/lite/BUILD.bazel
+@@ -1,3 +1,4 @@
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
+ load("//build_defs:cpp_opts.bzl", "COPTS")
+ 
+ cc_library(
+diff --git a/src/google/protobuf/compiler/kotlin/BUILD.bazel b/src/google/protobuf/compiler/kotlin/BUILD.bazel
+index 4f866ae02e1b7..5a1e1b727092b 100644
+--- a/src/google/protobuf/compiler/kotlin/BUILD.bazel
++++ b/src/google/protobuf/compiler/kotlin/BUILD.bazel
+@@ -1,3 +1,4 @@
++load("@rules_cc//cc:cc_library.bzl", "cc_library")
+ load("//build_defs:cpp_opts.bzl", "COPTS")
+ 
+ cc_library(
+diff --git a/src/google/protobuf/compiler/php/BUILD.bazel b/src/google/protobuf/compiler/php/BUILD.bazel
+index 930db4476125b..d41fe6d122adb 100644
+--- a/src/google/protobuf/compiler/php/BUILD.bazel
++++ b/src/google/protobuf/compiler/php/BUILD.bazel
+@@ -2,6 +2,7 @@
+ # Protocol Buffers Compiler - PHP code generator
+ ################################################################################
+ 
++load("@rules_cc//cc:cc_test.bzl", "cc_test")
+ load("@rules_cc//cc:defs.bzl", "cc_library")
+ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+ load("//build_defs:cpp_opts.bzl", "COPTS")
+diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel
+index e5766c2abd40b..116e44b76df9c 100644
+--- a/src/google/protobuf/compiler/rust/BUILD.bazel
++++ b/src/google/protobuf/compiler/rust/BUILD.bazel
+@@ -9,6 +9,8 @@
+ # Protocol Buffers Compiler - Rust code generator
+ ################################################################################
+ 
++load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
++load("@rules_cc//cc:cc_test.bzl", "cc_test")
+ load("@rules_cc//cc:defs.bzl", "cc_library")
+ load("//build_defs:cpp_opts.bzl", "COPTS")
+ load(
+diff --git a/toolchain/BUILD.bazel b/toolchain/BUILD.bazel
+index 524fa14390501..4cb056c75ff66 100644
+--- a/toolchain/BUILD.bazel
++++ b/toolchain/BUILD.bazel
+@@ -1,4 +1,6 @@
+ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
++load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain")
++load("@rules_cc//cc/toolchains:cc_toolchain_suite.bzl", "cc_toolchain_suite")
+ load(":cc_toolchain_config.bzl", "cc_toolchain_config")
+ 
+ package(default_visibility = ["//visibility:public"])

From 7a625caa6c06e5caa522f6402ec4ab2787307655 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Mon, 22 Sep 2025 08:05:51 -0700
Subject: [PATCH 024/251] Add JDK 25 (#319)

Closes #319

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/319 from fmeum:jdk-25 ddc4341c58485a94f3d9882e7afb56f0b9f16a74
PiperOrigin-RevId: 810016900
Change-Id: Icecc0ee3056f1ac357ad92b46c5509403c42adb1
---
 MODULE.bazel                     |  8 +++++
 java/bazel/repositories_util.bzl | 10 ++++++
 java/extensions.bzl              |  2 ++
 java/repositories.bzl            | 53 ++++++++++++++++++++++++++++++++
 toolchains/BUILD                 | 10 ++++--
 5 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 942c1bb2..ea1496b0 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -99,6 +99,14 @@ JDKS = {
         "win",
         "win_arm64",
     ],
+    "25": [
+        "linux",
+        "linux_aarch64",
+        "macos",
+        "macos_aarch64",
+        "win",
+        "win_arm64",
+    ],
 }
 
 REMOTE_JDK_REPOS = [(("remote_jdk" if version == "8" else "remotejdk") + version + "_" + platform) for version in JDKS for platform in JDKS[version]]
diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl
index 38170c13..5b05fb2e 100644
--- a/java/bazel/repositories_util.bzl
+++ b/java/bazel/repositories_util.bzl
@@ -86,6 +86,16 @@ _RELEASE_CONFIGS = {
             },
         },
     },
+    "25": {
+        "zulu": {
+            "release": "25.28.85-ca-jdk25.0.0",
+            "platforms": {
+                "linux": ["aarch64", "x86_64"],
+                "macos": ["aarch64", "x86_64"],
+                "windows": ["arm64", "x86_64"],
+            },
+        },
+    },
 }
 
 _STRIP_PREFIX_OVERRIDES = {
diff --git a/java/extensions.bzl b/java/extensions.bzl
index ad7978b6..a791d179 100644
--- a/java/extensions.bzl
+++ b/java/extensions.bzl
@@ -21,6 +21,7 @@ load(
     "remote_jdk11_repos",
     "remote_jdk17_repos",
     "remote_jdk21_repos",
+    "remote_jdk25_repos",
     "remote_jdk8_repos",
 )
 load("//toolchains:extensions.bzl", _java_repository = "java_repository")
@@ -32,6 +33,7 @@ def _toolchains_impl(module_ctx):
     remote_jdk11_repos()
     remote_jdk17_repos()
     remote_jdk21_repos()
+    remote_jdk25_repos()
 
     if bazel_features.external_deps.extension_metadata_has_reproducible:
         return module_ctx.extension_metadata(reproducible = True)
diff --git a/java/repositories.bzl b/java/repositories.bzl
index 2af22140..09da2ce6 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -325,6 +325,54 @@ _REMOTE_JDK_CONFIGS_LIST = [
         urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.6_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.6_7.tar.gz"],
         version = "21",
     ),
+    struct(
+        name = "remotejdk25_linux_aarch64",
+        target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
+        sha256 = "b60eb9d54c97ba4159547834a98cc5d016281dd2b3e60e7475cba4911324bcb4",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_aarch64.tar.gz"],
+        version = "25",
+    ),
+    struct(
+        name = "remotejdk25_linux",
+        target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
+        sha256 = "164d901e5a240b8c18516f5ab55bc11fc9689ab6e829045aea8467356dcdb340",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_x64.tar.gz"],
+        version = "25",
+    ),
+    struct(
+        name = "remotejdk25_macos_aarch64",
+        target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
+        sha256 = "73f64f6bad7c3df31fba740fbcbbbef7c1a5cedeffbb5df386dd79bc72aba9b6",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_aarch64.tar.gz"],
+        version = "25",
+    ),
+    struct(
+        name = "remotejdk25_macos",
+        target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
+        sha256 = "c2cde1d313d904b793c3760214eefa207ecca7df04e7c4084abdf1f6bbebc27a",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_x64.tar.gz"],
+        version = "25",
+    ),
+    struct(
+        name = "remotejdk25_win_arm64",
+        target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
+        sha256 = "f5f6d8a913695649e8e2607fe0dc79c81953b2583013ac1fb977c63cb4935bfb",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_aarch64.zip"],
+        version = "25",
+    ),
+    struct(
+        name = "remotejdk25_win",
+        target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
+        sha256 = "5efcf4e6a613cae06c8041de8a3695b7346aad0307d397b66bf55281cf1a5cb6",
+        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_x64.zip"],
+        version = "25",
+    ),
 ]
 
 def _make_version_to_remote_jdks():
@@ -369,6 +417,10 @@ def remote_jdk21_repos():
     """Imports OpenJDK 21 repositories."""
     _remote_jdk_repos_for_version("21")
 
+def remote_jdk25_repos():
+    """Imports OpenJDK 25 repositories."""
+    _remote_jdk_repos_for_version("25")
+
 def rules_java_dependencies():
     """DEPRECATED: No-op, kept for backwards compatibility"""
     print("DEPRECATED: use rules_java_dependencies() from rules_java_deps.bzl")  # buildifier: disable=print
@@ -384,6 +436,7 @@ def rules_java_toolchains(name = "toolchains"):
     remote_jdk11_repos()
     remote_jdk17_repos()
     remote_jdk21_repos()
+    remote_jdk25_repos()
     java_tools_repos()
 
     native.register_toolchains(
diff --git a/toolchains/BUILD b/toolchains/BUILD
index 9a1b2d33..d6d18bcc 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -353,12 +353,12 @@ alias(
     actual = ":toolchain",
 )
 
-RELEASES = (8, 9, 10, 11, 17, 21)
+RELEASES = (8, 9, 10, 11, 17, 21, 25)
 
 [
     default_java_toolchain(
         name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release,
-        configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
+        configuration = DEFAULT_TOOLCHAIN_CONFIGURATION if release <= 21 else DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_%d" % release},
         source_version = "%s" % release,
         target_version = "%s" % release,
     )
@@ -390,6 +390,12 @@ java_runtime_version_alias(
     visibility = ["//visibility:public"],
 )
 
+java_runtime_version_alias(
+    name = "remotejdk_25",
+    runtime_version = "remotejdk_25",
+    visibility = ["//visibility:public"],
+)
+
 java_runtime_version_alias(
     name = "jdk_8",
     runtime_version = "8",

From 1ee3e3508f99c81c94afac75cf25cb14977b0b56 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 23 Sep 2025 03:03:03 -0700
Subject: [PATCH 025/251] Release `@rules_java` `v8.16.0`

PiperOrigin-RevId: 810363784
Change-Id: I78a3ac45c37dd4f71047ab7f10e287d2a8700573
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index ea1496b0..adf1f140 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.15.2",
+    version = "8.16.0",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From 39cae30eea61d30ac6bbb5358d964cab059aa590 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Tue, 23 Sep 2025 05:27:59 -0700
Subject: [PATCH 026/251] Update the compilation JDK to 25 (#323)

This is necessary to support `--java_runtime_version=remotejdk_25` with lower `--java_language_version` values. JDK 21 already showed warnings when targeting Java 8.

Closes #323

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/323 from fmeum:jdk-25-default 8ab1d01eac01fcb221af113ede41fc7cdbac2581
PiperOrigin-RevId: 810400625
Change-Id: Id7b66c2a737f28b09316077a338ec9dd0e1928e1
---
 toolchains/BUILD                      | 2 +-
 toolchains/default_java_toolchain.bzl | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/toolchains/BUILD b/toolchains/BUILD
index d6d18bcc..3209930b 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -358,7 +358,7 @@ RELEASES = (8, 9, 10, 11, 17, 21, 25)
 [
     default_java_toolchain(
         name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release,
-        configuration = DEFAULT_TOOLCHAIN_CONFIGURATION if release <= 21 else DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_%d" % release},
+        configuration = DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_25"},
         source_version = "%s" % release,
         target_version = "%s" % release,
     )
diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index 4ec8961a..4f463937 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -98,6 +98,8 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict(
     reduced_classpath_incompatible_processors = [
         "dagger.hilt.processor.internal.root.RootProcessor",  # see b/21307381
     ],
+    # TODO: Update to JDK 25 after some time has passed - it no longer supports
+    # targeting JDK 7.
     java_runtime = Label("//toolchains:remotejdk_21"),
     oneversion = Label("//toolchains:one_version"),
 )

From ff92bd1d0c8e73f6af04075f838b7b905391e22e Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 23 Sep 2025 06:01:17 -0700
Subject: [PATCH 027/251] Release `@rules_java` `v8.16.1`

(ignore-relnotes)

PiperOrigin-RevId: 810408757
Change-Id: I0edd49b8efc9238303752f3b1f348d5f95111604
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index adf1f140..f900a930 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.16.0",
+    version = "8.16.1",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From ebfccdfef2ff740b16b0b2502bc49b3a8a36050d Mon Sep 17 00:00:00 2001
From: Benjamin Peterson 
Date: Wed, 24 Sep 2025 02:48:45 -0700
Subject: [PATCH 028/251] add some useful flags to the remotejdk fetching curl
 (#320)

Closes #320

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/320 from benjaminp:curl-flags 8e1e447c523659ca5a6a49a18413470397294934
PiperOrigin-RevId: 810796608
Change-Id: Iece85dba3804699bacec260da807b6486ca4888b
---
 java/bazel/BUILD.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/bazel/BUILD.bazel b/java/bazel/BUILD.bazel
index 68b3c1f1..225628e8 100644
--- a/java/bazel/BUILD.bazel
+++ b/java/bazel/BUILD.bazel
@@ -29,7 +29,7 @@ while read -r config; do
     TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX)
     IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config"
     echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr
-    curl --silent --fail -o $$TMP_FILE -L "$$primary_url" > /dev/stderr
+    curl --retry 5 --write-out '%{{onerror}}%{{url}}\n' --show-error --silent --fail -o $$TMP_FILE -L "$$primary_url" > /dev/stderr
     sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1`
     echo "struct("
     echo "  name = \\"$$name\\","

From 3cbc18e8e874b4d1d017d5e8b862d35624088b60 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Wed, 24 Sep 2025 02:58:52 -0700
Subject: [PATCH 029/251] Update abseil-cpp to remove override (#322)

Closes #322

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/322 from fmeum:patch-3 ab0eba8fd5356edef6f48bf247650a4664b6a5bc
PiperOrigin-RevId: 810799669
Change-Id: Ib4113c9090964f676def76dc67caf2125b7264da
---
 MODULE.bazel                               | 12 +-------
 third_party/abseil-cpp_load-cc-rules.patch | 36 ----------------------
 2 files changed, 1 insertion(+), 47 deletions(-)
 delete mode 100644 third_party/abseil-cpp_load-cc-rules.patch

diff --git a/MODULE.bazel b/MODULE.bazel
index f900a930..2da6b179 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -14,17 +14,7 @@ bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
 
 # Required by @remote_java_tools, which is loaded via module extension.
 bazel_dep(name = "rules_license", version = "0.0.3")
-bazel_dep(name = "abseil-cpp", version = "20250814.0", repo_name = "com_google_absl")
-
-# TODO: Remove this override after the next release of abseil-cpp.
-single_version_override(
-    module_name = "abseil-cpp",
-    patch_strip = 1,
-    patches = [
-        "//third_party:abseil-cpp_load-cc-rules.patch",
-    ],
-    version = "20250814.0",
-)
+bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
 
 single_version_override(
     module_name = "protobuf",
diff --git a/third_party/abseil-cpp_load-cc-rules.patch b/third_party/abseil-cpp_load-cc-rules.patch
deleted file mode 100644
index e3dfe2bb..00000000
--- a/third_party/abseil-cpp_load-cc-rules.patch
+++ /dev/null
@@ -1,36 +0,0 @@
-From 2370ccf579bd0fb4484c343389b8121c6b7f9bb8 Mon Sep 17 00:00:00 2001
-From: Keith Smiley 
-Date: Sat, 20 Sep 2025 20:02:06 -0700
-Subject: [PATCH] PR #1939: Add missing rules_cc loads
-
-Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1939
-
-This is required for use with bazel past this commit: https://github.com/bazelbuild/bazel/commit/71ca0ed111ff3d842a0d23bc3a46bd2e6745491d
-
-Most files do this already these were just missing
-
-Merge f7d58947afdb0549c9e5c287a5e5851a7d72e1e0 into 620d600442769b7ec4b61bd87667899908eec4ef
-
-Merging this change closes #1939
-
-COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1939 from keith:ks/add-missing-rules_cc-loads f7d58947afdb0549c9e5c287a5e5851a7d72e1e0
-PiperOrigin-RevId: 809556509
-Change-Id: I494a118b851685a03393485514a3b6fbe3a10597
----
- absl/debugging/BUILD.bazel | 3 +++
- 1 file changed, 3 insertions(+)
-
-diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel
-index ed7cc493e90..7cc053e783e 100644
---- a/absl/debugging/BUILD.bazel
-+++ b/absl/debugging/BUILD.bazel
-@@ -14,6 +14,9 @@
- # limitations under the License.
- #
- 
-+load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
-+load("@rules_cc//cc:cc_library.bzl", "cc_library")
-+load("@rules_cc//cc:cc_test.bzl", "cc_test")
- load(
-     "//absl:copts/configure_copts.bzl",
-     "ABSL_DEFAULT_COPTS",

From b19de64d5ebbf8548404be6f028c5a1ed336a826 Mon Sep 17 00:00:00 2001
From: Ed Schouten 
Date: Wed, 24 Sep 2025 07:46:29 -0700
Subject: [PATCH 030/251] Stop using the deprecated Label.workspace_name (#317)

Starting with Bazel 7 we should use Label.repo_name instead.

Closes #317

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/317 from EdSchouten:eschouten/20250909-repo-name 8d6a3e327ffbd9339ac5021c4e07d20454b39ea4
PiperOrigin-RevId: 810880486
Change-Id: I147c477448c29f6a421586cded7f4e05b137c480
---
 java/common/rules/java_runtime.bzl    | 4 ++--
 java/private/java_common_internal.bzl | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/java/common/rules/java_runtime.bzl b/java/common/rules/java_runtime.bzl
index 42321173..47a93435 100644
--- a/java/common/rules/java_runtime.bzl
+++ b/java/common/rules/java_runtime.bzl
@@ -54,7 +54,7 @@ JavaRuntimeInfo, _new_javaruntimeinfo = provider(
 )
 
 def _is_main_repo(label):
-    return label.workspace_name == ""
+    return label.repo_name == ""
 
 def _default_java_home(label):
     if _is_main_repo(label):
@@ -70,7 +70,7 @@ def _get_runfiles_java_executable(ctx, java_home, label):
     if paths.is_absolute(java_home) or _is_main_repo(label):
         return helper.get_relative(java_home, _get_bin_java(ctx))
     else:
-        repo_runfiles_path = "" if _is_main_repo(label) else helper.get_relative("..", label.workspace_name)
+        repo_runfiles_path = "" if _is_main_repo(label) else helper.get_relative("..", label.repo_name)
         return helper.get_relative(repo_runfiles_path, _get_bin_java(ctx))
 
 def _is_java_binary(path):
diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl
index 54f0c7bd..45b4f097 100644
--- a/java/private/java_common_internal.bzl
+++ b/java/private/java_common_internal.bzl
@@ -141,7 +141,7 @@ def compile(
     if ("com.google.devtools.build.runfiles.AutoBazelRepositoryProcessor" in
         plugin_info.plugins.processor_classes.to_list()):
         all_javac_opts.append(depset(
-            ["-Abazel.repository=" + ctx.label.workspace_name],
+            ["-Abazel.repository=" + ctx.label.repo_name],
             order = "preorder",
         ))
     system_bootclasspath = None

From 6a30ab8814486d8a6cdb59ffb1bf2cc63496fdfa Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Wed, 8 Oct 2025 04:26:16 -0700
Subject: [PATCH 031/251] Run the bootclasspath through ijar (#324)

This reduces disk space and cache usage and should speed up Turbine actions.

```
ls -lah bazel-out/darwin_arm64-fastbuild/bin/external/rules_java+/toolchains/platformclasspath*.jar
-r-xr-xr-x@ 1 fmeum    24M Sep 25 11:36 bazel-out/darwin_arm64-fastbuild/bin/external/rules_java+/toolchains/platformclasspath.jar
-r-xr-xr-x@ 1 fmeum   133M Sep 25 11:36 bazel-out/darwin_arm64-fastbuild/bin/external/rules_java+/toolchains/platformclasspath_unstripped.jar
```

Closes #324

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/324 from fmeum:ijar-bootclasspath 25b0af0de4cc8464f6fc24dd3fd46475e65bdc1e
PiperOrigin-RevId: 816643474
Change-Id: I27082108be70825ca691c17a0d1eedc7342ad064
---
 test/toolchains/bootclasspath_tests.bzl |  3 +++
 toolchains/bootclasspath.bzl            | 36 ++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/test/toolchains/bootclasspath_tests.bzl b/test/toolchains/bootclasspath_tests.bzl
index 5eb436a0..e7ad1cac 100644
--- a/test/toolchains/bootclasspath_tests.bzl
+++ b/test/toolchains/bootclasspath_tests.bzl
@@ -13,6 +13,9 @@ def _test_utf_8_environment(name):
 
 def _test_utf_8_environment_impl(env, target):
     for action in target.actions:
+        if action.mnemonic == "Ijar":
+            # ijar isn't sensitive to locales
+            continue
         env_subject = env.expect.where(action = action).that_dict(action.env)
         env_subject.keys().contains("LC_CTYPE")
         env_subject.get("LC_CTYPE", factory = subjects.str).contains("UTF-8")
diff --git a/toolchains/bootclasspath.bzl b/toolchains/bootclasspath.bzl
index d89aa171..5b4187c7 100644
--- a/toolchains/bootclasspath.bzl
+++ b/toolchains/bootclasspath.bzl
@@ -101,6 +101,21 @@ _bootclasspath_transition = transition(
     ],
 )
 
+def _run_ijar(*, actions, label, ijar, input, output):
+    args = actions.args()
+    args.add(input)
+    args.add(output)
+    args.add("--target_label", label)
+    actions.run(
+        inputs = [input],
+        outputs = [output],
+        executable = ijar,
+        arguments = [args],
+        progress_message = "Extracting interfaces from %{input}",
+        execution_requirements = _SUPPORTS_PATH_MAPPING,
+        mnemonic = "Ijar",
+    )
+
 _JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type")
 
 # Opt the Java bootstrap actions into path mapping:
@@ -138,7 +153,7 @@ def _bootclasspath_impl(ctx):
         use_default_shell_env = True,
     )
 
-    bootclasspath = ctx.outputs.output_jar
+    unstripped_bootclasspath = ctx.actions.declare_file("%s_unstripped.jar" % ctx.label.name)
 
     args = ctx.actions.args()
     args.add("-XX:+IgnoreUnrecognizedVMOptions")
@@ -148,7 +163,7 @@ def _bootclasspath_impl(ctx):
     args.add("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")
     args.add_all("-cp", [class_dir], expand_directories = False)
     args.add("DumpPlatformClassPath")
-    args.add(bootclasspath)
+    args.add(unstripped_bootclasspath)
 
     if ctx.attr.language_version_bootstrap_runtime:
         # The attribute is subject to a split transition.
@@ -201,12 +216,22 @@ Rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:bootstrap_runti
         executable = str(exec_javabase.java_executable_exec_path),
         mnemonic = "JavaToolchainCompileBootClasspath",
         inputs = inputs,
-        outputs = [bootclasspath],
+        outputs = [unstripped_bootclasspath],
         arguments = [args],
         env = env,
         execution_requirements = _SUPPORTS_PATH_MAPPING,
         use_default_shell_env = True,
     )
+
+    bootclasspath = ctx.outputs.output_jar
+    _run_ijar(
+        actions = ctx.actions,
+        label = ctx.label,
+        ijar = ctx.executable._ijar,
+        input = unstripped_bootclasspath,
+        output = bootclasspath,
+    )
+
     return [
         DefaultInfo(files = depset([bootclasspath])),
         java_common.BootClassPathInfo(
@@ -234,6 +259,11 @@ _bootclasspath = rule(
         "_allowlist_function_transition": attr.label(
             default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
         ),
+        "_ijar": attr.label(
+            default = "//toolchains:ijar",
+            cfg = "exec",
+            executable = True,
+        ),
         "_utf8_environment": attr.label(
             default = ":utf8_environment",
             cfg = "exec",

From 212b7abb395fe4ee0e80ea8511638ec690c92303 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 8 Oct 2025 05:03:45 -0700
Subject: [PATCH 032/251] Remove hasattr check from
 use_header_compilation_direct_deps logic

PiperOrigin-RevId: 816653694
Change-Id: I59255834bd625fa0cb4c99dde0e616c130cf7019
---
 java/private/java_common_internal.bzl | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl
index 45b4f097..7af3bf79 100644
--- a/java/private/java_common_internal.bzl
+++ b/java/private/java_common_internal.bzl
@@ -224,16 +224,11 @@ def compile(
     elif _should_use_header_compilation(ctx, java_toolchain):
         compile_jar = helper.derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jar")
 
-        # TODO: b/417791104 - remove hasattr check once Bazel 8.3.0 is released
-        if hasattr(ctx.fragments.java, "use_header_compilation_direct_deps") and ctx.fragments.java.use_header_compilation_direct_deps():
+        # TODO: b/417791104 - remove check after a Bazel release
+        if ctx.fragments.java.use_header_compilation_direct_deps():
             header_compilation_jar = helper.derive_output_file(ctx, output, name_suffix = "-tjar", extension = "jar")
-            header_compilation_extra_args = {
-                "header_compilation_jar": header_compilation_jar,
-                "header_compilation_direct_deps": header_compilation_direct_deps,
-            }
         else:
             header_compilation_jar = None
-            header_compilation_extra_args = {}
         compile_deps_proto = helper.derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jdeps")
         get_internal_java_common().create_header_compilation_action(
             ctx,
@@ -253,7 +248,8 @@ def compile(
             injecting_rule_kind,
             enable_direct_classpath,
             annotation_processor_additional_inputs,
-            **header_compilation_extra_args
+            header_compilation_jar,
+            header_compilation_direct_deps,
         )
     elif ctx.fragments.java.use_ijars():
         compile_jar = run_ijar(

From 3257e83974066f089202562d28603e06b06d3831 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 8 Oct 2025 05:30:18 -0700
Subject: [PATCH 033/251] Re-enable `ReturnValueIgnored` error prone check

The check was disabled (temporarily) to make progress at the time and never got re-enabled.

Fixes https://github.com/bazelbuild/rules_java/issues/284

PiperOrigin-RevId: 816661241
Change-Id: I8aa0951a7963e5ca4e22a93a4d0723aeb62ead40
---
 toolchains/default_java_toolchain.bzl | 2 --
 1 file changed, 2 deletions(-)

diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index 4f463937..f836f8fb 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -59,8 +59,6 @@ DEFAULT_JAVACOPTS = [
     "--should-stop=ifError=FLOW",  # See b/27049950, https://github.com/google/error-prone/issues/4595
     "-g",
     "-parameters",
-    # https://github.com/bazelbuild/bazel/issues/15219
-    "-Xep:ReturnValueIgnored:OFF",
     # https://github.com/bazelbuild/bazel/issues/16996
     "-Xep:IgnoredPureGetter:OFF",
     "-Xep:EmptyTopLevelDeclaration:OFF",

From 1ed307b1d1a5fb06decb7ae3af1622339dd24620 Mon Sep 17 00:00:00 2001
From: Farid Zakaria 
Date: Wed, 15 Oct 2025 02:07:46 -0700
Subject: [PATCH 034/251] Increase maxwarns to -1 (#291)

Please see https://github.com/bazelbuild/bazel/issues/25927#issuecomment-2825206105

It's important not to filter out any warnings otherwise the lint warnings are not surfaced and then any attempt to do `-Werror` can fail with what may be observed as spurious (affect other parts of the codebase).

This is maybe a "breaking change" only if someone has enabled `-Werror` and may now see additional errors -- although that was in fact their intention...

Closes #291

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/291 from fzakaria:patch-1 6938d218c5d8c3640f9c1d98cbf48e55b7f2639d
PiperOrigin-RevId: 819643216
Change-Id: I193e3fca51a56adc6ffa8623ef18729e633623e6
---
 toolchains/default_java_toolchain.bzl | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index f836f8fb..5d1d54a5 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -65,6 +65,9 @@ DEFAULT_JAVACOPTS = [
     "-Xep:LenientFormatStringValidation:OFF",
     "-Xep:ReturnMissingNullable:OFF",
     "-Xep:UseCorrectAssertInTests:OFF",
+    # Please see https://github.com/bazelbuild/bazel/issues/25927#issuecomment-2825206105
+    # we need to make sure not to filter any warnings so that Bazel can trigger them as errors.
+    "-Xmaxwarns -1",
 ]
 
 # If this is changed, the docs for "{,tool_}java_language_version" also

From 7ff9193af58807c9b77f3b7cd56063c9b8a9f028 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Wed, 15 Oct 2025 02:08:04 -0700
Subject: [PATCH 035/251] Fix test class determination error message (#326)

Closes #326

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/326 from fmeum:patch-5 cd3a7c35e6d9a027c6de7e0c6270a2ac8d62e88b
PiperOrigin-RevId: 819643398
Change-Id: I3d333388ae52c0e52da1e2ed56dbf5ef75ae5c4a
---
 java/bazel/rules/bazel_java_binary.bzl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl
index de25ab8f..4ee9c881 100644
--- a/java/bazel/rules/bazel_java_binary.bzl
+++ b/java/bazel/rules/bazel_java_binary.bzl
@@ -84,7 +84,7 @@ def bazel_base_binary_impl(ctx, is_test_rule_class):
             test_class = helper.primary_class(ctx)
         if test_class == None:
             fail("cannot determine test class. You might want to rename the " +
-                 " rule or add a 'test_class' attribute.")
+                 "rule or add a 'test_class' attribute.")
         jvm_flags.extend([
             "-ea",
             "-Dbazel.test_suite=" + helper.shell_escape(test_class),

From 6018c900f3aa553f97b9e3c0a5be4c4c6ea812a2 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 15 Oct 2025 06:24:18 -0700
Subject: [PATCH 036/251] Temporarily disable rules_java CI on
 macos/macos_arm64 due to infra issue

PiperOrigin-RevId: 819722046
Change-Id: I6f284a68c317f545d9b5dbd7b3e19ce846c826aa
---
 .bazelci/presubmit.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 7357c253..594ab399 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -46,7 +46,7 @@ flags_workspace_integration: &flags_workspace_integration
 buildifier: latest
 
 matrix:
-  all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
+  all_platforms: ["ubuntu2004", "windows"] # TODO: b/443213966 - re-enable macos/macos_arm64
   bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags
   modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions
 

From b4539a4977bc66620c319275b96e63020f8ad05c Mon Sep 17 00:00:00 2001
From: Googler 
Date: Thu, 16 Oct 2025 02:20:06 -0700
Subject: [PATCH 037/251] Revert: Temporarily disable rules_java CI on
 macos/macos_arm64 due to infra issue

PiperOrigin-RevId: 820135832
Change-Id: I0355ecf2044aef9609a2d0c4bc4e6cf82ed8d119
---
 .bazelci/presubmit.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 594ab399..7357c253 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -46,7 +46,7 @@ flags_workspace_integration: &flags_workspace_integration
 buildifier: latest
 
 matrix:
-  all_platforms: ["ubuntu2004", "windows"] # TODO: b/443213966 - re-enable macos/macos_arm64
+  all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
   bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags
   modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions
 

From 36264e47900e693a45b4388c396ca65e8be8a5a8 Mon Sep 17 00:00:00 2001
From: simonresch <65217285+simonresch@users.noreply.github.com>
Date: Fri, 17 Oct 2025 04:19:06 -0700
Subject: [PATCH 038/251] Update zulu JDKs to latest patch release (#327)
 (#328)

Closes #327

Closes #328

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/328 from simonresch:update-zulu-jdks 7478e8f79ef7b6f1569ab592c0865ca4bb1a51ad
PiperOrigin-RevId: 820632158
Change-Id: I49d4ed50ff8467f6305107b07b6bd8ea5dc736c2
---
 java/bazel/repositories_util.bzl |   8 +-
 java/repositories.bzl            | 132 +++++++++++++++----------------
 2 files changed, 70 insertions(+), 70 deletions(-)

diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl
index 5b05fb2e..e9a68f5e 100644
--- a/java/bazel/repositories_util.bzl
+++ b/java/bazel/repositories_util.bzl
@@ -18,7 +18,7 @@ visibility(["//test"])
 _RELEASE_CONFIGS = {
     "8": {
         "zulu": {
-            "release": "8.84.0.15-ca-jdk8.0.442",
+            "release": "8.88.0.19-ca-jdk8.0.462",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -34,7 +34,7 @@ _RELEASE_CONFIGS = {
     },
     "11": {
         "zulu": {
-            "release": "11.78.15-ca-jdk11.0.26",
+            "release": "11.82.19-ca-jdk11.0.28",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -56,7 +56,7 @@ _RELEASE_CONFIGS = {
     },
     "17": {
         "zulu": {
-            "release": "17.56.15-ca-jdk17.0.14",
+            "release": "17.60.17-ca-jdk17.0.16",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -72,7 +72,7 @@ _RELEASE_CONFIGS = {
     },
     "21": {
         "zulu": {
-            "release": "21.40.17-ca-jdk21.0.6",
+            "release": "21.44.17-ca-jdk21.0.8",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
diff --git a/java/repositories.bzl b/java/repositories.bzl
index 09da2ce6..ff473d4c 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -80,41 +80,41 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remote_jdk8_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "3ae6b27727a308c0c262a99e20af29c87aad7910de423db2607c44551b598e57",
-        strip_prefix = "zulu8.84.0.15-ca-jdk8.0.442-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-linux_aarch64.tar.gz"],
+        sha256 = "7f3a4f6a24f764259db98c69e759bf7cae95ce957dadd74117ed5d6037fcfcc7",
+        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "6e3bd4d911e6eb2d14e0b48e622b6909c76add0b51c51d11f5c2c3d2a045bcf3",
-        strip_prefix = "zulu8.84.0.15-ca-jdk8.0.442-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-linux_x64.tar.gz"],
+        sha256 = "af194163bd9c870321f06b134f447869daafe6aef5b92b49d15b2fbc03a3b999",
+        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_x64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "effa6d1bd4b6bce68328df66e063a97c2c4afeb0aa36fda4f85c434dd8246572",
-        strip_prefix = "zulu8.84.0.15-ca-jdk8.0.442-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-macosx_aarch64.tar.gz"],
+        sha256 = "abfb45c587b80646eedc679f5fd1c47f1851fd682a043adf5c46c0f55e4d2321",
+        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "52131294512042dd6356426202e6a4116536477281fe76cfc0a3a15fe0d6ff44",
-        strip_prefix = "zulu8.84.0.15-ca-jdk8.0.442-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-macosx_x64.tar.gz"],
+        sha256 = "e39adde0283ff1cb5c82193654c15688ea5ea4e6f38336d001c43d81d26c102c",
+        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_x64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_windows",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "551c0df372a4b01754e214c52d2bdc2e22e1582274a3ea0e4a27d77db6a9cbea",
-        strip_prefix = "zulu8.84.0.15-ca-jdk8.0.442-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.84.0.15-ca-jdk8.0.442-win_x64.zip"],
+        sha256 = "4811dd4bb476f7484d132cb6393ca58344c45d43b9547f4251b15c5b8d1fd580",
+        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-win_x64.zip"],
         version = "8",
     ),
     struct(
@@ -128,41 +128,41 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remotejdk11_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "f221d794325ab04382ba52250fc8fe8c4d384841a63bc2acd62d623a5bc53eb7",
-        strip_prefix = "zulu11.78.15-ca-jdk11.0.26-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-linux_aarch64.tar.gz"],
+        sha256 = "f90d9eb822f68cacd536144660b43402fc8a8e922358d67e84609d7828070e6b",
+        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_aarch64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "fdf95b001d50b03bc3ce5f4fe7dc96bec9f94e561f9ec722a149bd7995600449",
-        strip_prefix = "zulu11.78.15-ca-jdk11.0.26-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-linux_x64.tar.gz"],
+        sha256 = "b34a75da63dab5f61ac342290000c1a51de3023049e2b30da89393f5f0b79759",
+        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_x64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "3708badcc0c79fc1791e74b62478188a1f43c4f9a1e7d3e1bd4173da995479a3",
-        strip_prefix = "zulu11.78.15-ca-jdk11.0.26-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-macosx_aarch64.tar.gz"],
+        sha256 = "5b104e96bb41dc38b1605d701e4482003acffbe48e25e15ba0cb7a1611821aa7",
+        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_aarch64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "bb3884619c6f09ec5ca3ce43810c61ade647bb896f4120a6cf076ec993b5a1a0",
-        strip_prefix = "zulu11.78.15-ca-jdk11.0.26-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-macosx_x64.tar.gz"],
+        sha256 = "11c3a142f82ad10cd9e2bfc0884c36ee66de0ac1b3ed9c018e746345813f80c8",
+        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_x64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "2f48346ba05d0d1a31a6797cd0fd27a0492c0df0c90730c9eeca7fc6952a075c",
-        strip_prefix = "zulu11.78.15-ca-jdk11.0.26-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.78.15-ca-jdk11.0.26-win_x64.zip"],
+        sha256 = "728dbb971dc41be992aae950b89139e5d582f2ee7d918a06a69749fea6143fce",
+        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-win_x64.zip"],
         version = "11",
     ),
     struct(
@@ -192,49 +192,49 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remotejdk17_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "9fe5d08b20546e84af517cfefc7068f7a47e98473603782264e519f935977cb3",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-linux_aarch64.tar.gz"],
+        sha256 = "1cbb51dc9400814b8fbb79252762af5eba1f556e558128f2a4fca906b2ed04c8",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_aarch64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "37ab75b2f5da0ff0db973b31e9d9f14f729137a0a110abd6472ac8c6f2feabb6",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-linux_x64.tar.gz"],
+        sha256 = "e70822e4b77a9ffd57015b55f4bb645bba97b8f5247a792eceb95dbc7a5a55ab",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_x64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "c3b9bfb0a6dbe4c5d9efce6c46d3a89c92d7b07ba1bd0afc944612298ac284ec",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-macosx_aarch64.tar.gz"],
+        sha256 = "1e23895f8edddd86dbc20a2820b1bd11695e7a6ac37f1bcee90492341aa5b32d",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_aarch64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "ee1a55b6b63d62d1a24d420b1550ef1736fda36db0e612893d9d26eb1d7f1611",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-macosx_x64.tar.gz"],
+        sha256 = "6578d84c961b23f27bc7d504cb2fc45a47296bce382927d6485d404753a8a51a",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_x64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "dbf51756115f7591759b2ed6d9c0d79b3b770c1a13be476c99d64934a93ff422",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-win_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-win_aarch64.zip"],
+        sha256 = "2415163925968bfcc882e919e97f48c08eaf555947bb1b0b27291fd3fae1d462",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_aarch64.zip"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "11dbe0051cea65fbfc94e0074fbb26d81897f5aff2df69fed3784f380d0d9ec9",
-        strip_prefix = "zulu17.56.15-ca-jdk17.0.14-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-win_x64.zip"],
+        sha256 = "c51781710ff93fc7694668fe701c6b813aabda4e9dad6227a7d6734425b3b3ff",
+        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_x64.zip"],
         version = "17",
     ),
     struct(
@@ -256,49 +256,49 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remotejdk21_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "2cab003bad25100a00b818ce229455d35ece03fc2e69be32c9c1c03f90b2eb89",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-linux_aarch64.tar.gz"],
+        sha256 = "ff7f2edd1d5c153cb6cb493a3aa3523453e29a05ec513b25c24aa1477ec0c722",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_aarch64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "5daff61d307d18305a4022c56013cbaa8987a7dd103e310ebbeb75e0f3091a03",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-linux_x64.tar.gz"],
+        sha256 = "63f56bbb46958cf57352fba08f2755e0953799195e5545acc0c8a92920beff1e",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_x64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "1d6385f17ae2dc3b57a6d1b6fd6aeadafe1c7138bc744f62a767851eececd092",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-macosx_aarch64.tar.gz"],
+        sha256 = "d22ce05fea3e3f28c8c59f2c348bc78ee967bf1289a4fb28796cc0177ff6c8db",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_aarch64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "0b0f05e53e2b85f3881f1b8f5e3ef7e2e992796a1872afbc851b73127b16933d",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-macosx_x64.tar.gz"],
+        sha256 = "2af080500b5cc286a6353187c7c59b5aafcb3edc29c1c87d1fd71ba2d6a523f1",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_x64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "57c568355b97d288f12b720760d802b1a19c55e9b0707a5c2ad76d34fd893db8",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-win_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-win_aarch64.zip"],
+        sha256 = "76379d799e766fb7ea1cdaacc67aa87f75a118f863cc68ffe32c251be94ab4f4",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_aarch64.zip"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "a1360d2ab3ee9932b5cb20a2386d6b0fb1518a68c89a08739736c38a4debbdae",
-        strip_prefix = "zulu21.40.17-ca-jdk21.0.6-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.40.17-ca-jdk21.0.6-win_x64.zip"],
+        sha256 = "f47dbd00384cb759f86a066be7545e467e5764f4653a237c32c07da96dc1c43b",
+        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_x64.zip"],
         version = "21",
     ),
     struct(

From 402b1842d6e17e265c0b5c488f79edd851a202c2 Mon Sep 17 00:00:00 2001
From: Benjamin Peterson 
Date: Mon, 20 Oct 2025 02:55:06 -0700
Subject: [PATCH 039/251] upgrade java_tools to 17.0 and wire up linux aarch64
 prebuilts (#334)

https://github.com/bazelbuild/rules_java/issues/173

Closes #334

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/334 from benjaminp:benjamin-java_tools 830727a7d13ccff5aeee15b2c739ab86d71f5ad5
PiperOrigin-RevId: 821564837
Change-Id: I97b1f8fdf8a409110701e112197c4977eab03b6a
---
 .bazelci/presubmit.yml |  2 +-
 MODULE.bazel           |  1 +
 java/repositories.bzl  | 37 +++++++++++++++++++++----------------
 test/repo/MODULE.bazel |  1 +
 toolchains/BUILD       |  9 +++++++++
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 7357c253..b77fe7dc 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -46,7 +46,7 @@ flags_workspace_integration: &flags_workspace_integration
 buildifier: latest
 
 matrix:
-  all_platforms: ["ubuntu2004", "macos", "macos_arm64", "windows"]
+  all_platforms: ["rockylinux8_arm64", "ubuntu2004", "macos", "macos_arm64", "windows"]
   bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags
   modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions
 
diff --git a/MODULE.bazel b/MODULE.bazel
index 2da6b179..01888063 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -32,6 +32,7 @@ toolchains = use_extension("//java:extensions.bzl", "toolchains")
 # Declare remote java tools repos
 use_repo(toolchains, "remote_java_tools")
 use_repo(toolchains, "remote_java_tools_linux")
+use_repo(toolchains, "remote_java_tools_linux_aarch64")
 use_repo(toolchains, "remote_java_tools_windows")
 use_repo(toolchains, "remote_java_tools_darwin_x86_64")
 use_repo(toolchains, "remote_java_tools_darwin_arm64")
diff --git a/java/repositories.bzl b/java/repositories.bzl
index ff473d4c..bf2ae489 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -22,33 +22,38 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository")
 
 # visible for tests
 JAVA_TOOLS_CONFIG = {
-    "version": "v16.0",
+    "version": "v17.0",
     "release": "true",
     "artifacts": {
         "java_tools_linux": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_linux-v16.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_linux-v16.0.zip",
-            "sha": "7c360c60da9b9079e31f18de198f23a22555dfb7b6e91e3c6a7103127b1a8538",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_linux-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_linux-v17.0.zip",
+            "sha": "5f89d5d04b41dbe1d661836b6a76c468113e0080953bcd72aaf6711c7462b86a",
+        },
+        "java_tools_linux_aarch64": {
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_linux_aarch64-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_linux_aarch64-v17.0.zip",
+            "sha": "c36a17057e895b260cb8f2f7961ed7480812ab6923dab5a39f0c93263e2f76f2",
         },
         "java_tools_windows": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_windows-v16.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_windows-v16.0.zip",
-            "sha": "b41faa85fceeb2f852e48d51d000d3bf4f29da86ee61d0fc8cca46d297bccf22",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_windows-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_windows-v17.0.zip",
+            "sha": "3ae5075b228ce464c74bd23602a65016f662895556fa8952cba2995d50904c86",
         },
         "java_tools_darwin_x86_64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_darwin_x86_64-v16.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_darwin_x86_64-v16.0.zip",
-            "sha": "a41de64afb663bb4880af52b55886098241b9222ee8ec1a0f6258d006ba247fb",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_darwin_x86_64-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_darwin_x86_64-v17.0.zip",
+            "sha": "c65a181af0e723ed1a36c494aa0f70753f128adb7655a7b57f8f7e71217ad35c",
         },
         "java_tools_darwin_arm64": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools_darwin_arm64-v16.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools_darwin_arm64-v16.0.zip",
-            "sha": "b79900dccca7c26fbae9a38c4da80987445e07194517ec53e169c45f1a88c7be",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_darwin_arm64-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_darwin_arm64-v17.0.zip",
+            "sha": "00787917e359e2218953dbc30e228670e83fa20c4a0a5f914e0b6ecdee85fa9d",
         },
         "java_tools": {
-            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v16.0/java_tools-v16.0.zip",
-            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v16.0/java_tools-v16.0.zip",
-            "sha": "d8b126078705e91677db67b05f7b25ad6fa8865949e2dd38ff85e0553bfb0be2",
+            "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools-v17.0.zip",
+            "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools-v17.0.zip",
+            "sha": "9a441ca2d4ae393edd305b0e465b0ed8ee86b22123c41c26455fb856bf9bc897",
         },
     },
 }
diff --git a/test/repo/MODULE.bazel b/test/repo/MODULE.bazel
index 62109333..5f300800 100644
--- a/test/repo/MODULE.bazel
+++ b/test/repo/MODULE.bazel
@@ -27,6 +27,7 @@ use_repo(
     "remote_java_tools_darwin_arm64",
     "remote_java_tools_darwin_x86_64",
     "remote_java_tools_linux",
+    "remote_java_tools_linux_aarch64",
     "remote_java_tools_windows",
     "remotejdk11_linux",
     "remotejdk11_linux_aarch64",
diff --git a/toolchains/BUILD b/toolchains/BUILD
index 3209930b..bb6ecf7a 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -190,6 +190,7 @@ cc_library(
     )
     for OS in [
         "linux",
+        "linux_aarch64",
         "darwin_x86_64",
         "darwin_arm64",
         "windows",
@@ -207,6 +208,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":ijar_prebuilt_binary_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
         "//conditions:default": "@remote_java_tools//:ijar_cc_binary",
     }),
@@ -218,6 +220,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": "ijar_prebuilt_binary_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
     }),
 )
@@ -233,6 +236,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_singlejar_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
         "//conditions:default": "@remote_java_tools//:singlejar_cc_bin",
     }),
@@ -244,6 +248,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_singlejar_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
     }),
 )
@@ -259,6 +264,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_one_version_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_one_version_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_one_version_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_one_version_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":prebuilt_one_version_windows",
         "//conditions:default": "@remote_java_tools//:one_version_cc_bin",
     }),
@@ -270,6 +276,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_one_version_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_one_version_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_one_version_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_one_version_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":prebuilt_one_version_windows",
     }),
 )
@@ -285,6 +292,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows",
         "//conditions:default": "@remote_java_tools//:TurbineDirect",
     }),
@@ -296,6 +304,7 @@ alias(
         "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64",
         "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64",
         "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux",
+        "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64",
         "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows",
     }),
 )

From 76212e60692337b1bb10afa98a8163279fe99e17 Mon Sep 17 00:00:00 2001
From: Liz Looney 
Date: Wed, 22 Oct 2025 17:31:32 -0700
Subject: [PATCH 040/251] Include the srcjar (if there is one) in the
 _validation output group so blaze will check whether the srcjar file actually
 exists.

RELNOTES: If a java_import target's srcjar attribute refers to a source file, the file should exist.
PiperOrigin-RevId: 822801332
Change-Id: Ie5b364aa873a07b4cda6d528f1a1d69bdb5b9089
---
 .../rules/impl/bazel_java_import_impl.bzl     |  9 +++++-
 test/java/common/rules/java_import_tests.bzl  | 28 +++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl
index ce338cbd..7ca9cf7d 100644
--- a/java/common/rules/impl/bazel_java_import_impl.bzl
+++ b/java/common/rules/impl/bazel_java_import_impl.bzl
@@ -190,11 +190,18 @@ def bazel_java_import_rule(
     )
 
     output_group_src_jars = depset() if srcjar == None else depset([srcjar])
+
+    validation_group = []
+    if jdeps_artifact != None:
+        validation_group.append(jdeps_artifact)
+    if srcjar != None:
+        validation_group.append(srcjar)
+
     target["OutputGroupInfo"] = OutputGroupInfo(
         **{
             "_source_jars": output_group_src_jars,
             "_direct_source_jars": output_group_src_jars,
-            "_validation": depset() if jdeps_artifact == None else depset([jdeps_artifact]),
+            "_validation": depset(validation_group),
             "_hidden_top_level_INTERNAL_": target["ProguardSpecProvider"].specs,
         }
     )
diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl
index e949e173..37941efc 100644
--- a/test/java/common/rules/java_import_tests.bzl
+++ b/test/java/common/rules/java_import_tests.bzl
@@ -293,6 +293,33 @@ def _test_src_jars_impl(env, target):
         "{package}/library.srcjar",
     ])
 
+def _test_srcjar_added_to_validation_output_group(name):
+    util.helper_target(
+        java_import,
+        name = name + "/libraryjar_with_srcjar",
+        jars = ["import.jar"],
+        srcjar = "library.srcjar",
+    )
+
+    analysis_test(
+        name = name,
+        impl = _test_srcjar_added_to_validation_output_group_impl,
+        target = name + "/libraryjar_with_srcjar",
+        # Starlark rules are only used with Bazel 8 onwards.
+        attr_values = {"tags": ["min_bazel_8"]},
+    )
+
+def _test_srcjar_added_to_validation_output_group_impl(env, target):
+    assert_java_info = java_info_subject.from_target(env, target)
+    assert_java_info.outputs().source_output_jars().contains_exactly([
+        "{package}/library.srcjar",
+    ])
+
+    # Check that the srcjar is in the _validation output group.
+    env.expect.that_target(target).output_group("_validation").contains_at_least([
+        "{package}/library.srcjar",
+    ])
+
 def _test_from_genrule(name):
     target_name = name + "/library-jar"
     util.helper_target(
@@ -933,6 +960,7 @@ def java_import_tests(name):
             _test_java_library_allows_import_in_deps,
             _test_module_flags,
             _test_src_jars,
+            _test_srcjar_added_to_validation_output_group,
             _test_from_genrule,
             _test_transitive_dependencies,
             _test_exposes_java_provider,

From 4a1933abf58755b35775e3c5d0c87da0b742771e Mon Sep 17 00:00:00 2001
From: Googler 
Date: Thu, 23 Oct 2025 21:31:09 -0700
Subject: [PATCH 041/251] Migrate swig_include_scanning to Starlark. In native
 code, this is hard coded to True, but it's also used in starlark code. So, in
 native code, remove references to the flag. In Starlark code, refer to the
 starlark option. No OSS code here, so we can add the extra attribute to refer
 to the flag.

PiperOrigin-RevId: 823331236
Change-Id: I4adc25b86c531306e9d4491b985ea95400a875c3
---
 java/private/BUILD | 1 +
 1 file changed, 1 insertion(+)

diff --git a/java/private/BUILD b/java/private/BUILD
index 939fa753..bbed12b8 100644
--- a/java/private/BUILD
+++ b/java/private/BUILD
@@ -38,6 +38,7 @@ bzl_library(
         "//java/common/rules:toolchain_rules",
         "//java/common/rules/impl:java_helper_bzl",
         "@bazel_skylib//lib:paths",
+        "@bazel_skylib//rules:common_settings",
         "@rules_cc//cc:find_cc_toolchain_bzl",
         "@rules_cc//cc/common",
     ],

From a27004a53d7459992a77002ef8f2a6aaeb119590 Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim 
Date: Tue, 4 Nov 2025 05:21:58 -0800
Subject: [PATCH 042/251] Update JDKs to latest patch releases (#335)

Also print the original URLs, not the mirror URLs, as those have to be submitted as part of the mirror request.

Closes #335

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/335 from fmeum:21.0.9 6b7ba7b53eb1f56d7057efd3ae045ea3dabe2e41
PiperOrigin-RevId: 827922427
Change-Id: I211f3e51147acca8164d5d78276881cbedb9ffde
---
 java/bazel/repositories_util.bzl |  20 +--
 java/repositories.bzl            | 216 +++++++++++++++----------------
 test/check_remote_jdk_configs.sh |   4 +-
 3 files changed, 120 insertions(+), 120 deletions(-)

diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl
index e9a68f5e..924bb60f 100644
--- a/java/bazel/repositories_util.bzl
+++ b/java/bazel/repositories_util.bzl
@@ -18,7 +18,7 @@ visibility(["//test"])
 _RELEASE_CONFIGS = {
     "8": {
         "zulu": {
-            "release": "8.88.0.19-ca-jdk8.0.462",
+            "release": "8.90.0.19-ca-jdk8.0.472",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -34,7 +34,7 @@ _RELEASE_CONFIGS = {
     },
     "11": {
         "zulu": {
-            "release": "11.82.19-ca-jdk11.0.28",
+            "release": "11.84.17-ca-jdk11.0.29",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -42,13 +42,13 @@ _RELEASE_CONFIGS = {
             },
         },
         "adoptium": {
-            "release": "11.0.26+4",
+            "release": "11.0.28+6",
             "platforms": {
                 "linux": ["ppc64le", "s390x"],
             },
         },
         "microsoft": {
-            "release": "11.0.26",
+            "release": "11.0.28",
             "platforms": {
                 "windows": ["arm64"],
             },
@@ -56,7 +56,7 @@ _RELEASE_CONFIGS = {
     },
     "17": {
         "zulu": {
-            "release": "17.60.17-ca-jdk17.0.16",
+            "release": "17.62.17-ca-jdk17.0.17",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -64,7 +64,7 @@ _RELEASE_CONFIGS = {
             },
         },
         "adoptium": {
-            "release": "17.0.14+7",
+            "release": "17.0.16+8",
             "platforms": {
                 "linux": ["ppc64le", "s390x"],
             },
@@ -72,7 +72,7 @@ _RELEASE_CONFIGS = {
     },
     "21": {
         "zulu": {
-            "release": "21.44.17-ca-jdk21.0.8",
+            "release": "21.46.19-ca-jdk21.0.9",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -80,7 +80,7 @@ _RELEASE_CONFIGS = {
             },
         },
         "adoptium": {
-            "release": "21.0.6+7",
+            "release": "21.0.8+9",
             "platforms": {
                 "linux": ["ppc64le", "riscv64", "s390x"],
             },
@@ -88,7 +88,7 @@ _RELEASE_CONFIGS = {
     },
     "25": {
         "zulu": {
-            "release": "25.28.85-ca-jdk25.0.0",
+            "release": "25.30.17-ca-jdk25.0.1",
             "platforms": {
                 "linux": ["aarch64", "x86_64"],
                 "macos": ["aarch64", "x86_64"],
@@ -99,7 +99,7 @@ _RELEASE_CONFIGS = {
 }
 
 _STRIP_PREFIX_OVERRIDES = {
-    "remotejdk11_win_arm64": "jdk-11.0.26+4",
+    "remotejdk11_win_arm64": "jdk-11.0.28+6",
 }
 
 def _name_for_remote_jdk(version, os, cpu):
diff --git a/java/repositories.bzl b/java/repositories.bzl
index bf2ae489..82093756 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -85,41 +85,41 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remote_jdk8_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "7f3a4f6a24f764259db98c69e759bf7cae95ce957dadd74117ed5d6037fcfcc7",
-        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_aarch64.tar.gz"],
+        sha256 = "c372fb26480c052537125013cb0ba7336c404e5190ea8f6e2de247b676432a67",
+        strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "af194163bd9c870321f06b134f447869daafe6aef5b92b49d15b2fbc03a3b999",
-        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-linux_x64.tar.gz"],
+        sha256 = "6f9e3fa773829ac2553411fb0cdeb394980627c47c9ab8f8892d4b917b70e2dd",
+        strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "abfb45c587b80646eedc679f5fd1c47f1851fd682a043adf5c46c0f55e4d2321",
-        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_aarch64.tar.gz"],
+        sha256 = "823d547ab9508e3a2b8abd3c5de66a39a50a254dc5835747cf3c2617fbe55600",
+        strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "e39adde0283ff1cb5c82193654c15688ea5ea4e6f38336d001c43d81d26c102c",
-        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-macosx_x64.tar.gz"],
+        sha256 = "96fb7bc3a2babd7f807484b1b8f1dfb8cf2c61ea27b2d0630e2237088b0a5100",
+        strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz"],
         version = "8",
     ),
     struct(
         name = "remote_jdk8_windows",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "4811dd4bb476f7484d132cb6393ca58344c45d43b9547f4251b15c5b8d1fd580",
-        strip_prefix = "zulu8.88.0.19-ca-jdk8.0.462-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.88.0.19-ca-jdk8.0.462-win_x64.zip"],
+        sha256 = "ff90484103d3fdb9808f737af027586c8dbfa1aa8a310ce99b0b5e0517567aee",
+        strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip"],
         version = "8",
     ),
     struct(
@@ -133,249 +133,249 @@ _REMOTE_JDK_CONFIGS_LIST = [
     struct(
         name = "remotejdk11_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "f90d9eb822f68cacd536144660b43402fc8a8e922358d67e84609d7828070e6b",
-        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_aarch64.tar.gz"],
+        sha256 = "5a225a0fe0a92bc6c04c8c5aeb03c697c6fd114465829f23e494a2ad44fa1cc0",
+        strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "b34a75da63dab5f61ac342290000c1a51de3023049e2b30da89393f5f0b79759",
-        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-linux_x64.tar.gz"],
+        sha256 = "681b2e4bf7fedf4d20666fc2a954b83ff5675ccfb916c867267d29c85c2ee310",
+        strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "5b104e96bb41dc38b1605d701e4482003acffbe48e25e15ba0cb7a1611821aa7",
-        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_aarch64.tar.gz"],
+        sha256 = "09ed1734c2d88fadcb75fdbec1ba5467d32e7fa2b10894541aa8e3d3ce78dc2d",
+        strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "11c3a142f82ad10cd9e2bfc0884c36ee66de0ac1b3ed9c018e746345813f80c8",
-        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-macosx_x64.tar.gz"],
+        sha256 = "b7f5a37c47ed94af1c8ecf631b1dc6dec990958f3afd4222a7dd27d6ca1084bd",
+        strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "728dbb971dc41be992aae950b89139e5d582f2ee7d918a06a69749fea6143fce",
-        strip_prefix = "zulu11.82.19-ca-jdk11.0.28-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.82.19-ca-jdk11.0.28-win_x64.zip"],
+        sha256 = "f4002a8090662ff66bf9f3248604be0f9d226e964085bd59bbea4b8535df3de1",
+        strip_prefix = "zulu11.84.17-ca-jdk11.0.29-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_linux_ppc64le",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc64le"],
-        sha256 = "42c63651125a149cee2ba781300d75ffa67a25032f95038d50ee6d6177cb2e41",
-        strip_prefix = "jdk-11.0.26+4",
-        urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.26+4/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.26_4.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.26+4/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.26_4.tar.gz"],
+        sha256 = "e272abd162b3de68093630929453feba3e63a5ab1bbb912379f6a4aa968ef06a",
+        strip_prefix = "jdk-11.0.28+6",
+        urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28+6/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.28_6.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28+6/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.28_6.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_linux_s390x",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"],
-        sha256 = "0da13d990da34ecc666399cf0efa72a4b4e295f05c0686ea25a4a173a6f4414b",
-        strip_prefix = "jdk-11.0.26+4",
-        urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.26+4/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.26_4.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.26+4/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.26_4.tar.gz"],
+        sha256 = "ac3f94fdcc5372e90f44fad9cd03ec0e3fd3535fea06c120f85e4a7534c6de04",
+        strip_prefix = "jdk-11.0.28+6",
+        urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28+6/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.28_6.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28+6/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.28_6.tar.gz"],
         version = "11",
     ),
     struct(
         name = "remotejdk11_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "1d10cf760e4e011e830ef18ab28453a742ac84c046e4e77759e81b58716e6a8b",
-        strip_prefix = "jdk-11.0.26+4",
-        urls = ["https://aka.ms/download-jdk/microsoft-jdk-11.0.26-windows-aarch64.zip", "https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-11.0.26-windows-aarch64.zip"],
+        sha256 = "1e7bfad513a1c2930000db1af19c813460c7a788503c39a7f1f27375310880f8",
+        strip_prefix = "jdk-11.0.28+6",
+        urls = ["https://aka.ms/download-jdk/microsoft-jdk-11.0.28-windows-aarch64.zip", "https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-11.0.28-windows-aarch64.zip"],
         version = "11",
     ),
     struct(
         name = "remotejdk17_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "1cbb51dc9400814b8fbb79252762af5eba1f556e558128f2a4fca906b2ed04c8",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_aarch64.tar.gz"],
+        sha256 = "527b76fbd60e8f9644f6b70800d15160cdbd3344bc6fbf30d42e905f540a770c",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "e70822e4b77a9ffd57015b55f4bb645bba97b8f5247a792eceb95dbc7a5a55ab",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-linux_x64.tar.gz"],
+        sha256 = "1dcbbed73e95dc35f5c60402a84936f6830ff43c2a0dc0037a5657dbc25472c1",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "1e23895f8edddd86dbc20a2820b1bd11695e7a6ac37f1bcee90492341aa5b32d",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_aarch64.tar.gz"],
+        sha256 = "5558f7efe6297ecb20f422f31471555cd43e9499beb304b8f3ddc68796d2874b",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "6578d84c961b23f27bc7d504cb2fc45a47296bce382927d6485d404753a8a51a",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-macosx_x64.tar.gz"],
+        sha256 = "e6b2fb0cd3f929225a179c2fb2813abd1834f839a3b4c8cdcb36067aa16b6f83",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "2415163925968bfcc882e919e97f48c08eaf555947bb1b0b27291fd3fae1d462",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-win_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_aarch64.zip"],
+        sha256 = "c1bba9148907348da93b0de2c9abd56bd180efcb6b1f35068ab9785015fcd74b",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "c51781710ff93fc7694668fe701c6b813aabda4e9dad6227a7d6734425b3b3ff",
-        strip_prefix = "zulu17.60.17-ca-jdk17.0.16-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.60.17-ca-jdk17.0.16-win_x64.zip"],
+        sha256 = "bd8a942bb543f109a28d3eadf3ec2f29a3ee28ab53506e31d2858292f63c6949",
+        strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_linux_ppc64le",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc64le"],
-        sha256 = "f4cb9ee5906a44d110fa381310cd7181d95498d27087d449e7e9b74bddd9def2",
-        strip_prefix = "jdk-17.0.14+7",
-        urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.14+7/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.14_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.14+7/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.14_7.tar.gz"],
+        sha256 = "eb020f74e00870379522be0b44fc6322c2214e77971c258400c8b5af704d5c0a",
+        strip_prefix = "jdk-17.0.16+8",
+        urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16+8/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.16_8.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16+8/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.16_8.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk17_linux_s390x",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"],
-        sha256 = "3a1d896eb3a737020e5ec95ec3206b1ca36cb365538382289d3fb46d14303648",
-        strip_prefix = "jdk-17.0.14+7",
-        urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.14+7/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.14_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.14+7/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.14_7.tar.gz"],
+        sha256 = "03dd99d34d2d1b88395765df3acbec2cb81de286f64b1d9e6df3682bee365168",
+        strip_prefix = "jdk-17.0.16+8",
+        urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16+8/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.16_8.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16+8/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.16_8.tar.gz"],
         version = "17",
     ),
     struct(
         name = "remotejdk21_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "ff7f2edd1d5c153cb6cb493a3aa3523453e29a05ec513b25c24aa1477ec0c722",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_aarch64.tar.gz"],
+        sha256 = "a826a93c18d4388ec8d5d4057f5bb1b5c60f00ffc875ed299dea17aa947555ee",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "63f56bbb46958cf57352fba08f2755e0953799195e5545acc0c8a92920beff1e",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-linux_x64.tar.gz"],
+        sha256 = "67e810b31427ac0ff1c249473595066a00bdf0f9265df186c32905d5f75c93b8",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "d22ce05fea3e3f28c8c59f2c348bc78ee967bf1289a4fb28796cc0177ff6c8db",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_aarch64.tar.gz"],
+        sha256 = "b56112ad12d3dfe62802840655ecf198fe4ca48729824c939d65a69e803536c7",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "2af080500b5cc286a6353187c7c59b5aafcb3edc29c1c87d1fd71ba2d6a523f1",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-macosx_x64.tar.gz"],
+        sha256 = "3d870d823e3e101189b00ad975188c0321e31056ac8ca8b487bcf4454f3b5cfe",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "76379d799e766fb7ea1cdaacc67aa87f75a118f863cc68ffe32c251be94ab4f4",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-win_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_aarch64.zip"],
+        sha256 = "1210b169db7b40d7305a94d41ab3eb87aaee51108b43f8f7f36f0c2865107790",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "f47dbd00384cb759f86a066be7545e467e5764f4653a237c32c07da96dc1c43b",
-        strip_prefix = "zulu21.44.17-ca-jdk21.0.8-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.44.17-ca-jdk21.0.8-win_x64.zip"],
+        sha256 = "0c9812c0fe527b59f48c70cb527035c8a7abe620b31f776b4ddc21bddc1cd067",
+        strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_linux_ppc64le",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc64le"],
-        sha256 = "163724b70b86d5a8461f85092165a9cc5a098ed900fee90d1b0c0be9607ae3d2",
-        strip_prefix = "jdk-21.0.6+7",
-        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.6_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.6_7.tar.gz"],
+        sha256 = "a24e869b8e563fd7b9f7776f6686ca5d737c8d1c3c33c9b72836935709b44a34",
+        strip_prefix = "jdk-21.0.8+9",
+        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.8_9.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.8_9.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_linux_riscv64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:riscv64"],
-        sha256 = "203796e4ba2689aa921b5e0cdc9e02984d88622f80fcb9acb05a118b05007be8",
-        strip_prefix = "jdk-21.0.6+7",
-        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_riscv64_linux_hotspot_21.0.6_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_riscv64_linux_hotspot_21.0.6_7.tar.gz"],
+        sha256 = "8171d95189e675e297b5cb96c7ac6247ab4e9f48da82b13f491fc46ef5d97836",
+        strip_prefix = "jdk-21.0.8+9",
+        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_riscv64_linux_hotspot_21.0.8_9.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_riscv64_linux_hotspot_21.0.8_9.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk21_linux_s390x",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"],
-        sha256 = "5ba742c87d48fcf564def56812699f6499a1cfd3535ae43286e94e74b8165faf",
-        strip_prefix = "jdk-21.0.6+7",
-        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.6_7.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.6+7/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.6_7.tar.gz"],
+        sha256 = "a84e3cbf8bb5f8a313e06b790c7bc388687ba00262e981f5e33432ebd4d34356",
+        strip_prefix = "jdk-21.0.8+9",
+        urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.8_9.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8+9/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.8_9.tar.gz"],
         version = "21",
     ),
     struct(
         name = "remotejdk25_linux_aarch64",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
-        sha256 = "b60eb9d54c97ba4159547834a98cc5d016281dd2b3e60e7475cba4911324bcb4",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-linux_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_aarch64.tar.gz"],
+        sha256 = "8c5321f16d9f1d8149f83e4e9ff8ca5d9e94320b92d205e6db42a604de3d1140",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-linux_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_aarch64.tar.gz"],
         version = "25",
     ),
     struct(
         name = "remotejdk25_linux",
         target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
-        sha256 = "164d901e5a240b8c18516f5ab55bc11fc9689ab6e829045aea8467356dcdb340",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-linux_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-linux_x64.tar.gz"],
+        sha256 = "471b3e62bdffaed27e37005d842d8639f10d244ccce1c7cdebf7abce06c8313e",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-linux_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_x64.tar.gz"],
         version = "25",
     ),
     struct(
         name = "remotejdk25_macos_aarch64",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
-        sha256 = "73f64f6bad7c3df31fba740fbcbbbef7c1a5cedeffbb5df386dd79bc72aba9b6",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-macosx_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_aarch64.tar.gz"],
+        sha256 = "126061d6046b0c0df0472b361ca7895951d34fef1dd522f222f2c7d8738a39d8",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-macosx_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_aarch64.tar.gz"],
         version = "25",
     ),
     struct(
         name = "remotejdk25_macos",
         target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"],
-        sha256 = "c2cde1d313d904b793c3760214eefa207ecca7df04e7c4084abdf1f6bbebc27a",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-macosx_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-macosx_x64.tar.gz"],
+        sha256 = "0154482b317aa63d5158a358e2fab7f0fd6c3c0ba2000b05655c3bcbdd202584",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-macosx_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_x64.tar.gz"],
         version = "25",
     ),
     struct(
         name = "remotejdk25_win_arm64",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"],
-        sha256 = "f5f6d8a913695649e8e2607fe0dc79c81953b2583013ac1fb977c63cb4935bfb",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-win_aarch64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_aarch64.zip"],
+        sha256 = "4883cf39e8d83679c8a051ace4dd72759d97195a72aaa6727a83bd4bcb97b022",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-win_aarch64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_aarch64.zip"],
         version = "25",
     ),
     struct(
         name = "remotejdk25_win",
         target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
-        sha256 = "5efcf4e6a613cae06c8041de8a3695b7346aad0307d397b66bf55281cf1a5cb6",
-        strip_prefix = "zulu25.28.85-ca-jdk25.0.0-win_x64",
-        urls = ["https://cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.28.85-ca-jdk25.0.0-win_x64.zip"],
+        sha256 = "72844ba8dddf9259ab9cfda9d515d0c850179705f74278a75973d73f0c5b2d2b",
+        strip_prefix = "zulu25.30.17-ca-jdk25.0.1-win_x64",
+        urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_x64.zip"],
         version = "25",
     ),
 ]
diff --git a/test/check_remote_jdk_configs.sh b/test/check_remote_jdk_configs.sh
index 1b58c96d..b1c509fe 100755
--- a/test/check_remote_jdk_configs.sh
+++ b/test/check_remote_jdk_configs.sh
@@ -40,12 +40,12 @@ for config in "$@"; do
     fi
     if [[ -n "${mirror_url}" ]]; then
       echo "checking mirror: ${mirror_url}"
-      curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+=("${mirror_url}"); }
+      curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+=("${url}"); }
     fi
 done
 
 if [[ ${#_MISSING_MIRRORS[@]} -gt 0 ]]; then
-  echo "Missing mirror URLs:"
+  echo "URLs that aren't mirrored:"
   for m in "${_MISSING_MIRRORS[@]}"; do
     echo "  ${m}"
   done

From 9073b05c545ceceedbbca001a7429c5d8a6d2219 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 4 Nov 2025 06:03:51 -0800
Subject: [PATCH 043/251] Update `rules_cc` dep to fix CI

(ignore-relnotes)

PiperOrigin-RevId: 827934830
Change-Id: Ic3416c7bcb65b8c07a2e3e62556bc02ea7e5fb9f
---
 MODULE.bazel | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 01888063..789d597d 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -6,7 +6,14 @@ module(
 )
 
 bazel_dep(name = "platforms", version = "0.0.11")
-bazel_dep(name = "rules_cc", version = "0.2.8")
+bazel_dep(name = "rules_cc", version = "0.2.13")
+archive_override(
+    module_name = "rules_cc",
+    integrity = "sha256-y3RA9zEyB7HqBXVTgrlFmvfJARcEDzILe2ugNGC4ZrE=",
+    strip_prefix = "rules_cc-b5a65591334f74371f4d75003768957a740cd868",
+    urls = ["https://github.com/bazelbuild/rules_cc/archive/b5a65591334f74371f4d75003768957a740cd868.tar.gz"],
+)
+
 bazel_dep(name = "bazel_features", version = "1.30.0")
 bazel_dep(name = "bazel_skylib", version = "1.6.1")
 bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf")

From 8bf8a941c42906219e93fc678ebbfcbe7c38bdef Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 4 Nov 2025 06:30:43 -0800
Subject: [PATCH 044/251] Release `@rules_java` `v9.0.0`

(ignore-relnotes)

PiperOrigin-RevId: 827944657
Change-Id: I9eaeb89b7a3481e1eee615f718683ffb7ff955f7
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 789d597d..e19c4e3f 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "8.16.1",
+    version = "9.0.0",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From b1376ddb00e54b7c381c43fc74dc7c269cb8d057 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Tue, 4 Nov 2025 11:14:52 -0800
Subject: [PATCH 045/251] Add support for an unstripped bootclasspath

Running the bootclasspath through ijar was added in https://github.com/bazelbuild/rules_java/pull/324 and was always enabled. This change lets us selectively disable it. This ensures we don't end up depending on the prebuilt ijar in the non-prebuilt toolchain case. This is also needed to bootstrap bazel where we don't have access to `@remote_java_tools`

PiperOrigin-RevId: 828056087
Change-Id: I38402112139221cea606b64110fb1854795a8113
---
 toolchains/BUILD                      | 11 +++++++++++
 toolchains/bootclasspath.bzl          |  3 ++-
 toolchains/default_java_toolchain.bzl |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/toolchains/BUILD b/toolchains/BUILD
index bb6ecf7a..41a4f533 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -351,6 +351,17 @@ bootclasspath(
     }),
 )
 
+bootclasspath(
+    name = "platformclasspath_unstripped",
+    src = "DumpPlatformClassPath.java",
+    java_runtime_alias = ":current_java_runtime",
+    language_version_bootstrap_runtime = select({
+        ":incompatible_language_version_bootclasspath_enabled": ":language_version_bootstrap_runtime",
+        "//conditions:default": None,
+    }),
+    strip = False,
+)
+
 default_java_toolchain(
     name = "toolchain",
     configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
diff --git a/toolchains/bootclasspath.bzl b/toolchains/bootclasspath.bzl
index 5b4187c7..945a73c3 100644
--- a/toolchains/bootclasspath.bzl
+++ b/toolchains/bootclasspath.bzl
@@ -231,7 +231,7 @@ Rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:bootstrap_runti
         input = unstripped_bootclasspath,
         output = bootclasspath,
     )
-
+    bootclasspath = bootclasspath if ctx.attr.strip else unstripped_bootclasspath
     return [
         DefaultInfo(files = depset([bootclasspath])),
         java_common.BootClassPathInfo(
@@ -256,6 +256,7 @@ _bootclasspath = rule(
             cfg = "exec",
             allow_single_file = True,
         ),
+        "strip": attr.bool(default = True),
         "_allowlist_function_transition": attr.label(
             default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
         ),
diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index 5d1d54a5..b08e4919 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -143,6 +143,7 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
     singlejar = [Label("@remote_java_tools//:singlejar_cc_bin")],
     header_compiler_direct = [Label("@remote_java_tools//:TurbineDirect")],
     oneversion = Label("@remote_java_tools//:one_version_cc_bin"),
+    bootclasspath = [Label("//toolchains:platformclasspath_unstripped")],
 )
 
 def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs):

From 67e83ef06b854fef89cec3a96c158afd99456055 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 5 Nov 2025 01:22:54 -0800
Subject: [PATCH 046/251] Release `@rules_java` `v9.0.1`

(ignore-relnotes)

PiperOrigin-RevId: 828351782
Change-Id: I12177c7b9e28ad8673f4da4d6cc3bffbb5fadc41
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index e19c4e3f..34928f56 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "9.0.0",
+    version = "9.0.1",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From a27c7de6503387a5d3675d373979c40621413552 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 5 Nov 2025 02:07:13 -0800
Subject: [PATCH 047/251] Cut the dependency on ijar when not stripping the
 bootclasspath

Rule deps are fetched eagerly, even if unused, so we need to actually cut the edge to ijar when not stripping for bazel bootstrapping to succeed.

Unfortunately, with the way Bazel integration tests are set up, there's no way to test this with Bazel without making a release. I manually verified that `bazel query deps()` reports the right results and the targets build correctly.

```
$ bazel query 'deps(//toolchains:platformclasspath, 1)'
//:license
//toolchains:DumpPlatformClassPath.java
//toolchains:current_java_runtime
//toolchains:ijar
//toolchains:incompatible_language_version_bootclasspath_enabled
//toolchains:language_version_bootstrap_runtime
//toolchains:platformclasspath
//toolchains:utf8_environment
@bazel_tools//tools/allowlists/function_transition_allowlist:function_transition_allowlist
@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type

$ bazel query 'deps(//toolchains:platformclasspath_unstripped, 1)'
//:license
//toolchains:DumpPlatformClassPath.java
//toolchains:current_java_runtime
//toolchains:incompatible_language_version_bootclasspath_enabled
//toolchains:language_version_bootstrap_runtime
//toolchains:platformclasspath_unstripped
//toolchains:utf8_environment
@bazel_tools//tools/allowlists/function_transition_allowlist:function_transition_allowlist
@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type
```

(ignore-relnotes)

PiperOrigin-RevId: 828368783
Change-Id: Ie29eea882ad41e4efa8f1dd752679a221a239ae1
---
 toolchains/bootclasspath.bzl | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/toolchains/bootclasspath.bzl b/toolchains/bootclasspath.bzl
index 945a73c3..93da5de8 100644
--- a/toolchains/bootclasspath.bzl
+++ b/toolchains/bootclasspath.bzl
@@ -224,14 +224,16 @@ Rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:bootstrap_runti
     )
 
     bootclasspath = ctx.outputs.output_jar
-    _run_ijar(
-        actions = ctx.actions,
-        label = ctx.label,
-        ijar = ctx.executable._ijar,
-        input = unstripped_bootclasspath,
-        output = bootclasspath,
-    )
-    bootclasspath = bootclasspath if ctx.attr.strip else unstripped_bootclasspath
+    if ctx.attr.strip:
+        _run_ijar(
+            actions = ctx.actions,
+            label = ctx.label,
+            ijar = ctx.executable._ijar,
+            input = unstripped_bootclasspath,
+            output = bootclasspath,
+        )
+    else:
+        ctx.actions.symlink(output = bootclasspath, target_file = unstripped_bootclasspath)
     return [
         DefaultInfo(files = depset([bootclasspath])),
         java_common.BootClassPathInfo(
@@ -241,6 +243,9 @@ Rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:bootstrap_runti
         OutputGroupInfo(jar = [bootclasspath]),
     ]
 
+def _compute_ijar(strip):
+    return Label("//toolchains:ijar") if strip else None
+
 _bootclasspath = rule(
     implementation = _bootclasspath_impl,
     attrs = {
@@ -261,7 +266,7 @@ _bootclasspath = rule(
             default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
         ),
         "_ijar": attr.label(
-            default = "//toolchains:ijar",
+            default = _compute_ijar,
             cfg = "exec",
             executable = True,
         ),

From 56177d044e0d4e193c14549dd1d0c0c0c78f3f01 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 5 Nov 2025 02:15:26 -0800
Subject: [PATCH 048/251] Release `@rules_java` `v9.0.2`

(ignore-relnotes)

PiperOrigin-RevId: 828371518
Change-Id: I1b578bf0d5e32ae4097b3c2885bb68ff8cfe64c9
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index 34928f56..cfae101b 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "9.0.1",
+    version = "9.0.2",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From 9b84026b40dfdba5e57db814dc70793fca0e66cc Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 5 Nov 2025 03:25:26 -0800
Subject: [PATCH 049/251] Rename target to avoid artifact conflict

The `bootclasspath` rule internally generates a (intermediate) `{name}_unstripped.jar` artifact which conflicts with the output of the `//toolchains:platformclasspath_unstripped` target

(ignore-relnotes)

PiperOrigin-RevId: 828390314
Change-Id: I3a5a21a52c6697c1497db295277a2c96c52df5a9
---
 toolchains/BUILD                      | 2 +-
 toolchains/default_java_toolchain.bzl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/toolchains/BUILD b/toolchains/BUILD
index 41a4f533..0f3ef2bf 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -352,7 +352,7 @@ bootclasspath(
 )
 
 bootclasspath(
-    name = "platformclasspath_unstripped",
+    name = "platformclasspath_nostrip",
     src = "DumpPlatformClassPath.java",
     java_runtime_alias = ":current_java_runtime",
     language_version_bootstrap_runtime = select({
diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index b08e4919..7b113ef6 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -143,7 +143,7 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
     singlejar = [Label("@remote_java_tools//:singlejar_cc_bin")],
     header_compiler_direct = [Label("@remote_java_tools//:TurbineDirect")],
     oneversion = Label("@remote_java_tools//:one_version_cc_bin"),
-    bootclasspath = [Label("//toolchains:platformclasspath_unstripped")],
+    bootclasspath = [Label("//toolchains:platformclasspath_nostrip")],
 )
 
 def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs):

From 8427063e872aa3bddf1d091c3faa129d9395a261 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 5 Nov 2025 03:38:11 -0800
Subject: [PATCH 050/251] Release `@rules_java` `v9.0.3`

(ignore-relnotes)

PiperOrigin-RevId: 828394095
Change-Id: I5d740a68b8293ef2da450371416867002e9794e2
---
 MODULE.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MODULE.bazel b/MODULE.bazel
index cfae101b..0de3d565 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
 module(
     name = "rules_java",
-    version = "9.0.2",
+    version = "9.0.3",
     bazel_compatibility = [">=6.4.0"],
     compatibility_level = 1,
 )

From aa153f057a204f6212ec766029ff9df2b4c0285c Mon Sep 17 00:00:00 2001
From: Googler 
Date: Fri, 14 Nov 2025 02:14:36 -0800
Subject: [PATCH 051/251] Execute the `check_remote_java_tools_configs_test`
 only on a single platform

The test is platform / bazel independent and is wasteful to run on all platforms / bazel combinations

(ignore-relnotes)

PiperOrigin-RevId: 832226923
Change-Id: I74ede6ccf16f8f5ec4331ee258495e386188026d
---
 .bazelci/presubmit.yml | 1 +
 test/BUILD.bazel       | 1 +
 2 files changed, 2 insertions(+)

diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index b77fe7dc..3a603039 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -135,4 +135,5 @@ tasks:
       - "git commit --allow-empty -m 'Fake commit message for testing'"
     test_targets:
       - "//test:check_remote_jdk_configs_test"
+      - "//test:check_remote_java_tools_configs_test"
       - "//test:check_release_notes_test"
diff --git a/test/BUILD.bazel b/test/BUILD.bazel
index 084ff40c..964c77cb 100644
--- a/test/BUILD.bazel
+++ b/test/BUILD.bazel
@@ -48,6 +48,7 @@ sh_test(
         ])
         for name, config in JAVA_TOOLS_CONFIG["artifacts"].items()
     ],
+    tags = ["manual"],  # explicitly tested only on Linux
 )
 
 sh_test(

From 6ea00a46a9e5498d748d6ae843c87e21c9e8b1d9 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Fri, 14 Nov 2025 08:11:13 -0800
Subject: [PATCH 052/251] Internal change

PiperOrigin-RevId: 832321939
Change-Id: Icb4f46359980d7ed1734ade08d2834ef3265c289
---
 java/java_single_jar.bzl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/java/java_single_jar.bzl b/java/java_single_jar.bzl
index 48aa45c3..e51329ef 100644
--- a/java/java_single_jar.bzl
+++ b/java/java_single_jar.bzl
@@ -59,6 +59,9 @@ def _java_single_jar(ctx):
     if ctx.attr.multi_release:
         args.add("--multi_release")
 
+    if ctx.attr.exclude_pattern:
+        args.add("--exclude_pattern", ctx.attr.exclude_pattern)
+
     ctx.actions.run(
         inputs = inputs,
         outputs = [ctx.outputs.jar],
@@ -110,6 +113,9 @@ java_single_jar = rule(
             Whether to omit the build-data.properties file generated
             by default."""),
         "multi_release": attr.bool(default = True, doc = """Whether to enable Multi-Release output jars."""),
+        "exclude_pattern": attr.string(default = "", doc = """
+            A regex pattern of files to exclude from the jar.
+        """),
         "_singlejar": attr.label(
             default = Label("//toolchains:singlejar"),
             cfg = "exec",

From d4159a222e9ac0635aa3b2b39d1f0ab655846344 Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 19 Nov 2025 02:49:53 -0800
Subject: [PATCH 053/251] Fix bazel version check in
 `local_java_repository.bzl`

With the latest rolling release version hitting `10.x`, we can no longer rely on simple string comparision.

PiperOrigin-RevId: 834204982
Change-Id: Idb37877d983287787b6b997d4a01385164608a46
---
 toolchains/local_java_repository.bzl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/toolchains/local_java_repository.bzl b/toolchains/local_java_repository.bzl
index 075f54d6..ba526a14 100644
--- a/toolchains/local_java_repository.bzl
+++ b/toolchains/local_java_repository.bzl
@@ -14,6 +14,7 @@
 
 """Rules for importing a local JDK."""
 
+load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge")
 load("//java/toolchains:java_runtime.bzl", "java_runtime")
 load(":default_java_toolchain.bzl", "default_java_toolchain")
 
@@ -235,8 +236,7 @@ local_java_runtime(
 )
 """ % (local_java_runtime_name, runtime_name, java_home, version)
 
-    bazel = native.bazel_version
-    if not bazel or bazel >= "7":
+    if _bazel_version_ge("7.0.0"):
         # Bazel 7+ uses @platforms//host for the host platform.
         load_host_constraints = 'load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")\n'
     else:

From 19936576119852560c1bd21bcd29a0ae1d629cbc Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 19 Nov 2025 04:32:14 -0800
Subject: [PATCH 054/251] Enable C++ rules and providers

PiperOrigin-RevId: 834233788
Change-Id: Id4d969bb98ec7121be1d41f7e4eed179090e5d63
---
 java/BUILD | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/java/BUILD b/java/BUILD
index 452c7654..18bbe33e 100644
--- a/java/BUILD
+++ b/java/BUILD
@@ -83,9 +83,10 @@ filegroup(
         ":core_rules",
         ":java_single_jar",
         ":rules",
+        # TODO(bazel-team@): Add for_bazel_tests from rules_cc
+        "//java/common:for_bazel_tests",
         "//java/bazel:for_bazel_tests",  # copybara-use-repo-external-label
         "//java/bazel/rules:for_bazel_tests",  # copybara-use-repo-external-label
-        "//java/common:for_bazel_tests",
         "//java/private:for_bazel_tests",
         "//java/toolchains:for_bazel_tests",
         "@bazel_skylib//:test_deps",

From 37b099cfd27de53495aea44763a16cd23ff929df Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 19 Nov 2025 07:40:00 -0800
Subject: [PATCH 055/251] Refactor java_single_jar to allow custom output
 names.

PiperOrigin-RevId: 834288538
Change-Id: I18bd305a6870e74db4136f3dc78ffebefaaf91cd
---
 java/java_single_jar.bzl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/java/java_single_jar.bzl b/java/java_single_jar.bzl
index e51329ef..bfdd21c0 100644
--- a/java/java_single_jar.bzl
+++ b/java/java_single_jar.bzl
@@ -40,7 +40,7 @@ def _java_single_jar(ctx):
     args.use_param_file("@%s")
     args.set_param_file_format("multiline")
     args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines)
-    args.add("--output", ctx.outputs.jar)
+    args.add("--output", ctx.outputs.output)
     args.add("--normalize")
 
     # Deal with limitation of singlejar flags: tool's default behavior is
@@ -64,15 +64,15 @@ def _java_single_jar(ctx):
 
     ctx.actions.run(
         inputs = inputs,
-        outputs = [ctx.outputs.jar],
+        outputs = [ctx.outputs.output],
         arguments = [args],
-        progress_message = "Merging into %s" % ctx.outputs.jar.short_path,
+        progress_message = "Merging into %s" % ctx.outputs.output.short_path,
         mnemonic = "JavaSingleJar",
         executable = ctx.executable._singlejar,
         use_default_shell_env = True,
     )
 
-    files = depset([ctx.outputs.jar])
+    files = depset([ctx.outputs.output])
     providers = [DefaultInfo(
         files = files,
         runfiles = ctx.runfiles(transitive_files = files),
@@ -81,6 +81,11 @@ def _java_single_jar(ctx):
         providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs))
     return providers
 
+def _init(name, **kwargs):
+    if "output" not in kwargs:
+        kwargs["output"] = name + ".jar"
+    return kwargs
+
 java_single_jar = rule(
     attrs = {
         "deps": attr.label_list(
@@ -122,10 +127,9 @@ java_single_jar = rule(
             allow_single_file = True,
             executable = True,
         ),
+        "output": attr.output(),
     },
-    outputs = {
-        "jar": "%{name}.jar",
-    },
+    initializer = _init,
     implementation = _java_single_jar,
     doc = """
 Collects Java dependencies and jar files into a single jar

From 542f5fa212472bbb4fd65cd2bb7ae08bedd79b4a Mon Sep 17 00:00:00 2001
From: Googler 
Date: Wed, 19 Nov 2025 21:48:40 -0800
Subject: [PATCH 056/251] Delete non-actionable `TODO`

(ignore-relnotes)

PiperOrigin-RevId: 834586059
Change-Id: I6669c6c4aaf48d632ddb1f2c6abd675160c55438
---
 java/BUILD | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/java/BUILD b/java/BUILD
index 18bbe33e..452c7654 100644
--- a/java/BUILD
+++ b/java/BUILD
@@ -83,10 +83,9 @@ filegroup(
         ":core_rules",
         ":java_single_jar",
         ":rules",
-        # TODO(bazel-team@): Add for_bazel_tests from rules_cc
-        "//java/common:for_bazel_tests",
         "//java/bazel:for_bazel_tests",  # copybara-use-repo-external-label
         "//java/bazel/rules:for_bazel_tests",  # copybara-use-repo-external-label
+        "//java/common:for_bazel_tests",
         "//java/private:for_bazel_tests",
         "//java/toolchains:for_bazel_tests",
         "@bazel_skylib//:test_deps",

From e515e2df8deda5dac0deb419cd46eafc9e224d3c Mon Sep 17 00:00:00 2001
From: Googler 
Date: Mon, 24 Nov 2025 04:27:05 -0800
Subject: [PATCH 057/251] Fix typo in `java_binary.bzl` comment.

Removed an extra closing parenthesis from the `classpath_resources` attribute documentation.

PiperOrigin-RevId: 836167105
Change-Id: I22a2c9f6790f2a448e0ce983afcae2ae56f4d3cb
---
 java/common/rules/java_binary.bzl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/common/rules/java_binary.bzl b/java/common/rules/java_binary.bzl
index cdd79f29..609ca974 100644
--- a/java/common/rules/java_binary.bzl
+++ b/java/common/rules/java_binary.bzl
@@ -303,7 +303,7 @@ will be ignored for this target.
         "classpath_resources": attr.label_list(
             allow_files = True,
             doc = """
-DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)
+DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY
 

A list of resources that must be located at the root of the java tree. This attribute's only purpose is to support third-party libraries that require that their resources be From b55339e359675d03a4f1cc001f1840d0b27966df Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 26 Nov 2025 02:20:52 -0800 Subject: [PATCH 058/251] Drop support for Bazel 6 Bazel 6.5.0 is EOL in Dec 2025 (https://bazel.build/release#support-matrix) Also bump other supported bazel versions to their latest minor/patch in CI PiperOrigin-RevId: 837025814 Change-Id: If9ea408f3f1df8e47279453d1bca2db9fefeb57e --- .bazelci/presubmit.yml | 43 +++++------------------------------------- MODULE.bazel | 2 +- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 3a603039..4fe6a435 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -14,15 +14,6 @@ build_targets: &build_targets - "-//java/docs/..." - "-//test:docs_up_to_date_test" -build_targets_bazel6: &build_targets_bazel6 - - "//:all" - # build java_tools from source - - "@remote_java_tools//:ijar_cc_binary" - - "@remote_java_tools//:one_version_cc_bin" - - "@remote_java_tools//:proguard" - - "@remote_java_tools//:singlejar_cc_bin" - - "//examples/..." - build_targets_integration: &build_targets_integration - "//..." - "//:bin_deploy.jar" @@ -32,10 +23,6 @@ test_targets: &test_targets # TODO: re-enable docs after moving them out of https://bazel.build/reference/be/java - "-//test:docs_up_to_date_test" -test_targets_bazel6: &test_targets_bazel6 - - "//test/java/..." - - "-//test/java/private/..." - test_target_integration: &test_target_integration - "//:MyTest" @@ -47,7 +34,7 @@ buildifier: latest matrix: all_platforms: ["rockylinux8_arm64", "ubuntu2004", "macos", "macos_arm64", "windows"] - bazel: ["7.6.1", "8.4.0", "last_green"] # Bazel 6 tested separately, needs different flags + bazel: ["7.7.1", "8.4.2", "last_green"] modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions tasks: @@ -60,8 +47,8 @@ tasks: test_targets: *test_targets # Bazel 8.x build_and_test_bazel8: - name: "Bazel 8.4.0" - bazel: "8.4.0" + name: "Bazel 8.4.2" + bazel: "8.4.2" platform: ${{ all_platforms }} build_targets: *build_targets test_targets: *test_targets @@ -69,33 +56,13 @@ tasks: - "--test_tag_filters=-min_bazel_9" # Bazel 7.x build_and_test_bazel7: - name: "Bazel 7.6.1" - bazel: "7.6.1" + name: "Bazel 7.7.1" + bazel: "7.7.1" platform: ${{ all_platforms }} build_targets: *build_targets test_targets: *test_targets test_flags: - "--test_tag_filters=-min_bazel_8,-min_bazel_9" -# Bazel 6.x - build_and_test_bazel6: - name: "Bazel 6.5.0" - bazel: 6.5.0 - platform: ${{ all_platforms }} - build_targets: *build_targets_bazel6 - test_targets: *test_targets_bazel6 - test_flags: - - "--test_tag_filters=-min_bazel_7,-min_bazel_8,-min_bazel_9" - ubuntu2004_integration_bazel6: - name: "Integration w/ Bazel 6.5.0" - bazel: 6.5.0 - platform: ${{ all_platforms }} - working_directory: "test/repo" - shell_commands: - - sh setup.sh - batch_commands: - - setup.bat - build_targets: *build_targets_integration - test_targets: *test_target_integration # Integration tests integration_build_and_test: diff --git a/MODULE.bazel b/MODULE.bazel index 0de3d565..8c2a672a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,7 @@ module( name = "rules_java", version = "9.0.3", - bazel_compatibility = [">=6.4.0"], + bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From b5b4100314da5732854f8c72d0e1c1b2902100ab Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 26 Nov 2025 03:00:41 -0800 Subject: [PATCH 059/251] Prepare to remove _LEGACY_ANY_TYPE_ATTRS workaround in java_toolchain PiperOrigin-RevId: 837039389 Change-Id: Ib484a607424abb1558651f73d7e12bea9ec8ad47 --- java/common/rules/java_toolchain.bzl | 1 + test/java/toolchains/java_toolchain_tests.bzl | 8 +++---- toolchains/default_java_toolchain.bzl | 24 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index fe32fc36..6aed2ecd 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -240,6 +240,7 @@ def _extract_singleton_list_value(dict, key): else: dict[key] = None +# TODO: b/463873596 - remove this in Bazel 10 _LEGACY_ANY_TYPE_ATTRS = [ "genclass", "deps_checker", diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 378ba910..928ce00b 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -13,12 +13,12 @@ def _declare_java_toolchain(*, name, **kwargs): util.helper_target( java_toolchain, name = name, - genclass = [kwargs.get("genclass", "default_genclass.jar")], + genclass = kwargs.get("genclass", "default_genclass.jar"), jacocorunner = kwargs.get("jacocorunner", None), - javabuilder = [kwargs.get("javabuilder", "default_javabuilder.jar")], + javabuilder = kwargs.get("javabuilder", "default_javabuilder.jar"), java_runtime = kwargs["java_runtime"], - ijar = [kwargs.get("ijar", "default_ijar.jar")], - singlejar = [kwargs.get("singlejar", "default_singlejar.jar")], + ijar = kwargs.get("ijar", "default_ijar.jar"), + singlejar = kwargs.get("singlejar", "default_singlejar.jar"), ) def _test_jacocorunner(name): diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index 7b113ef6..f4f83f66 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -77,11 +77,11 @@ _DEFAULT_JAVA_LANGUAGE_VERSION = "11" # Default java_toolchain parameters _BASE_TOOLCHAIN_CONFIGURATION = dict( forcibly_disable_header_compilation = False, - genclass = [Label("@remote_java_tools//:GenClass")], - header_compiler = [Label("@remote_java_tools//:TurbineDirect")], - header_compiler_direct = [Label("//toolchains:turbine_direct")], - ijar = [Label("//toolchains:ijar")], - javabuilder = [Label("@remote_java_tools//:JavaBuilder")], + genclass = Label("@remote_java_tools//:GenClass"), + header_compiler = Label("@remote_java_tools//:TurbineDirect"), + header_compiler_direct = Label("//toolchains:turbine_direct"), + ijar = Label("//toolchains:ijar"), + javabuilder = Label("@remote_java_tools//:JavaBuilder"), javac_supports_workers = True, jacocorunner = Label("@remote_java_tools//:jacoco_coverage_runner_filegroup"), jvm_opts = BASE_JDK9_JVM_OPTS, @@ -90,7 +90,7 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict( "-XX:+UseParallelGC", ], misc = DEFAULT_JAVACOPTS, - singlejar = [Label("//toolchains:singlejar")], + singlejar = Label("//toolchains:singlejar"), # Code to enumerate target JVM boot classpath uses host JVM. Because # java_runtime-s are involved, its implementation is in @bazel_tools. bootclasspath = [Label("//toolchains:platformclasspath")], @@ -121,7 +121,7 @@ DEFAULT_TOOLCHAIN_CONFIGURATION = _BASE_TOOLCHAIN_CONFIGURATION # However it does allow using a wider range of `--host_javabase`s, including # versions newer than the current JDK. VANILLA_TOOLCHAIN_CONFIGURATION = dict( - javabuilder = [Label("@remote_java_tools//:VanillaJavaBuilder")], + javabuilder = Label("@remote_java_tools//:VanillaJavaBuilder"), jvm_opts = [], java_runtime = None, ) @@ -132,16 +132,16 @@ VANILLA_TOOLCHAIN_CONFIGURATION = dict( # same, otherwise the binaries will not work on the execution # platform. PREBUILT_TOOLCHAIN_CONFIGURATION = dict( - ijar = [Label("//toolchains:ijar_prebuilt_binary")], - singlejar = [Label("//toolchains:prebuilt_singlejar")], + ijar = Label("//toolchains:ijar_prebuilt_binary"), + singlejar = Label("//toolchains:prebuilt_singlejar"), oneversion = Label("//toolchains:prebuilt_one_version"), ) # The new toolchain is using all the tools from sources. NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict( - ijar = [Label("@remote_java_tools//:ijar_cc_binary")], - singlejar = [Label("@remote_java_tools//:singlejar_cc_bin")], - header_compiler_direct = [Label("@remote_java_tools//:TurbineDirect")], + ijar = Label("@remote_java_tools//:ijar_cc_binary"), + singlejar = Label("@remote_java_tools//:singlejar_cc_bin"), + header_compiler_direct = Label("@remote_java_tools//:TurbineDirect"), oneversion = Label("@remote_java_tools//:one_version_cc_bin"), bootclasspath = [Label("//toolchains:platformclasspath_nostrip")], ) From ad7f833dddb5fd7f62ccfbb19b9603a1b4429f4b Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 27 Nov 2025 01:53:48 -0800 Subject: [PATCH 060/251] Cleanup unused Bazel 6 test filtering Follow up to https://github.com/bazelbuild/rules_java/commit/b55339e359675d03a4f1cc001f1840d0b27966df [^1] PiperOrigin-RevId: 837439832 Change-Id: I8413040e00ce2b4338b2b0dd6802c8c990edb9e1 --- test/java/common/java_common_tests.bzl | 6 ------ test/java/common/java_info_tests.bzl | 1 - test/java/common/java_plugin_info_tests.bzl | 1 - test/java/common/rules/java_binary_tests.bzl | 4 ---- test/java/common/rules/java_import_tests.bzl | 2 -- test/java/common/rules/java_test_tests.bzl | 3 --- test/java/toolchains/java_runtime_tests.bzl | 6 ------ 7 files changed, 23 deletions(-) diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index d4528df8..2eaf00de 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -91,8 +91,6 @@ def _test_compile_exports_with_sources(name): name = name, impl = _test_compile_exports_with_sources_impl, target = target_name, - # Bazel 6 JavaInfo doesn't expose compile_time_java_dependencies - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_compile_exports_with_sources_impl(env, target): @@ -138,7 +136,6 @@ def _test_compile_extend_compile_time_jdeps(name): name = name, impl = _test_compile_extend_compile_time_jdeps_impl, target = name + "/foo", - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_compile_extend_compile_time_jdeps_impl(env, target): @@ -181,7 +178,6 @@ def _test_compile_extend_compile_time_jdeps_rule_outputs(name): "bar": name + "/bar", "baz": name + "/baz", }, - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_compile_extend_compile_time_jdeps_rule_outputs_impl(env, targets): @@ -234,7 +230,6 @@ def _test_compile_bootclasspath(name): name = name, impl = _test_compile_bootclasspath_impl, target = name + "/custom", - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_compile_bootclasspath_impl(env, target): @@ -269,7 +264,6 @@ def _test_compile_override_with_empty_bootclasspath(name): name = name, impl = _test_compile_override_with_empty_bootclasspath_impl, target = name + "/custom", - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_compile_override_with_empty_bootclasspath_impl(env, target): diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index 5d3c6663..a646e112 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -1255,7 +1255,6 @@ def _output_source_jars_returns_depset_test(name): name = name, impl = _output_source_jars_returns_depset_test_impl, target = target_name, - attr_values = {"tags": ["min_bazel_7"]}, # changed in Bazel 7 ) def _output_source_jars_returns_depset_test_impl(env, target): diff --git a/test/java/common/java_plugin_info_tests.bzl b/test/java/common/java_plugin_info_tests.bzl index c3b8b378..ed742f13 100644 --- a/test/java/common/java_plugin_info_tests.bzl +++ b/test/java/common/java_plugin_info_tests.bzl @@ -124,7 +124,6 @@ def _test_without_processor_class(name): name = name, impl = _test_without_processor_class_impl, target = target_name, - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_without_processor_class_impl(env, target): diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 08386ad1..97a85713 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -18,7 +18,6 @@ def _test_java_binary_provides_binary_java_info(name): name = name, impl = _test_java_binary_provides_binary_java_info_impl, target = Label(":bin"), - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_java_binary_provides_binary_java_info_impl(env, target): @@ -150,9 +149,6 @@ def _test_java_binary_propagates_direct_native_libraries(name): name = name, impl = _test_java_binary_propagates_direct_native_libraries_impl, target = name + "/binary", - # in Bazel 6, the windows stub was created by a bespoke, native and - # opaque-to-Starlark LauncherFileWriteAction - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_java_binary_propagates_direct_native_libraries_impl(env, target): diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl index 37941efc..7afbc77b 100644 --- a/test/java/common/rules/java_import_tests.bzl +++ b/test/java/common/rules/java_import_tests.bzl @@ -775,8 +775,6 @@ def _test_neverlink_is_populated(name): name = name, impl = _test_neverlink_is_populated_impl, target = target_name, - # in Bazel 6, JavaInfo._neverlink isn't exposed to Starlark - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_neverlink_is_populated_impl(env, target): diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 4cc39ca2..f4db104b 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -56,9 +56,6 @@ def _test_java_test_propagates_direct_native_libraries(name): name = name, impl = _test_java_test_propagates_direct_native_libraries_impl, target = name + "/binary", - # in Bazel 6, the windows stub was created by a bespoke, native and - # opaque-to-Starlark LauncherFileWriteAction - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_java_test_propagates_direct_native_libraries_impl(env, target): diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 4f1ec88a..f5014966 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -38,8 +38,6 @@ def _test_with_absolute_java_home(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/java_runtime_toolchain")], }, - # Bazel 6 doesn't accept Label's for the transition above - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_with_absolute_java_home_impl(env, target): @@ -80,8 +78,6 @@ def _test_with_hermetic_java_home(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/java_runtime_toolchain")], }, - # Bazel 6 doesn't accept Label's for the transition above - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_with_hermetic_java_home_impl(env, target): @@ -129,8 +125,6 @@ def _test_with_generated_java_executable(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/java_runtime_toolchain")], }, - # Bazel 6 doesn't accept Label's for the transition above - attr_values = {"tags": ["min_bazel_7"]}, ) def _test_with_generated_java_executable_impl(env, target): From 4a9881b8fd0c61dca10eef559d5d7b9a1940156f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 27 Nov 2025 02:30:25 -0800 Subject: [PATCH 061/251] remove Bazel 6 branch (#337) Now that https://github.com/bazelbuild/rules_java/commit/b55339e359675d03a4f1cc001f1840d0b27966df has landed, remove Bazel 6-specific branch. Closes #337 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/337 from benjaminp:bazel-6 f4c631a13d6e7c3bf55e29b52cc418f4b663e141 PiperOrigin-RevId: 837452933 Change-Id: I68e8171ae4e70600cc82d09af75c15726f6d7ee6 --- toolchains/local_java_repository.bzl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/toolchains/local_java_repository.bzl b/toolchains/local_java_repository.bzl index ba526a14..769c2d19 100644 --- a/toolchains/local_java_repository.bzl +++ b/toolchains/local_java_repository.bzl @@ -14,7 +14,6 @@ """Rules for importing a local JDK.""" -load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("//java/toolchains:java_runtime.bzl", "java_runtime") load(":default_java_toolchain.bzl", "default_java_toolchain") @@ -236,17 +235,10 @@ local_java_runtime( ) """ % (local_java_runtime_name, runtime_name, java_home, version) - if _bazel_version_ge("7.0.0"): - # Bazel 7+ uses @platforms//host for the host platform. - load_host_constraints = 'load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")\n' - else: - # Bazel 6 uses @local_config_platform instead, but it's being removed in Bazel 9. - load_host_constraints = 'load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")\n' - repository_ctx.file( "BUILD.bazel", 'load("@rules_java//toolchains:local_java_repository.bzl", "local_java_runtime")\n' + - load_host_constraints + + 'load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")\n' + build_file + local_java_runtime_macro, ) From 4f806ff8d9b30a7d7dcaf501205b340dba62c74c Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 1 Dec 2025 00:40:54 -0800 Subject: [PATCH 062/251] Avoid quadratic time on string concatenation in _get_native_deps_helper. PiperOrigin-RevId: 838641853 Change-Id: Ic2447584007194e7209b856bd97b318bfa34e14a --- java/common/rules/impl/java_helper.bzl | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 683bf609..d54c8f64 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -170,18 +170,15 @@ def _get_shared_native_deps_path( method below is only ensured by validations in the CppLinkAction.Builder.build() method. """ - fp = "" - for artifact in linker_inputs: - fp += artifact.short_path - fp += str(len(link_opts)) - for opt in link_opts: - fp += opt - for artifact in linkstamps: - fp += artifact.short_path - for artifact in build_info_artifacts: - fp += artifact.short_path - for feature in features: - fp += feature + fp = [] + + # join() is faster than concatenating many strings individually + fp += [a.short_path for a in linker_inputs] + fp.append(str(len(link_opts))) + fp += link_opts + fp += [a.short_path for a in linkstamps] + fp += [a.short_path for a in build_info_artifacts] + fp += features # Sharing of native dependencies may cause an ActionConflictException when ThinLTO is # disabled for test and test-only targets that are statically linked, but enabled for other @@ -190,9 +187,9 @@ def _get_shared_native_deps_path( # this, we allow creation of multiple artifacts for the shared native library - one shared # among the test and test-only targets where ThinLTO is disabled, and the other shared among # other targets where ThinLTO is enabled. - fp += "1" if is_test_target_partially_disabled_thin_lto else "0" + fp.append("1" if is_test_target_partially_disabled_thin_lto else "0") - fingerprint = "%x" % hash(fp) + fingerprint = "%x" % hash("".join(fp)) return "_nativedeps/" + fingerprint def _check_and_get_one_version_attribute(ctx, attr): From b6856588ba834750a1e66b2dd1b274a1f09f66a5 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 1 Dec 2025 01:11:10 -0800 Subject: [PATCH 063/251] Release `rules_java` `v9.1.0` PiperOrigin-RevId: 838651324 Change-Id: I6a176d71930b2e8909f96a8a47a21a7e0a068211 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 8c2a672a..24653fe2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.0.3", + version = "9.1.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 8bf8bcaca17fc15ba4fff3229d4eead4b653214a Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 1 Dec 2025 03:55:59 -0800 Subject: [PATCH 064/251] Extract utility methods used in the loading phase from `impl/java_helper.bzl` into a separate bzl file Methods used only by a single other load-affecting bzl file are inlined there instead. This way `impl/java_helper.bzl` is only loaded from bzl files used during rule implementations and should not be needed for the loading-phase, so making changes to this file don't invalidate the results of `blaze query`[^1]. PiperOrigin-RevId: 838701557 Change-Id: If462c46b1b8f2e5be12322a8af7d1a27e392bdfd --- java/common/rules/BUILD | 15 ++ java/common/rules/impl/BUILD | 7 + java/common/rules/impl/java_helper.bzl | 234 +----------------- java/common/rules/java_helper.bzl | 212 ++++++++++++++++ .../rules/java_package_configuration.bzl | 2 +- java/common/rules/java_runtime.bzl | 2 +- java/common/rules/java_toolchain.bzl | 2 +- java/private/BUILD | 25 +- java/private/java_common.bzl | 2 +- java/private/java_common_internal.bzl | 49 +++- 10 files changed, 311 insertions(+), 239 deletions(-) create mode 100644 java/common/rules/java_helper.bzl diff --git a/java/common/rules/BUILD b/java/common/rules/BUILD index 12006384..5bb5c2fb 100644 --- a/java/common/rules/BUILD +++ b/java/common/rules/BUILD @@ -25,6 +25,12 @@ bzl_library( visibility = ["//visibility:private"], ) +bzl_library( + name = "java_helper_bzl", + srcs = ["java_helper.bzl"], + visibility = ["//java:__subpackages__"], +) + bzl_library( name = "core_rules", srcs = [ @@ -58,6 +64,15 @@ bzl_library( "//java:__subpackages__", "@compatibility_proxy//:__pkg__", ], + deps = [ + ":java_helper_bzl", + "//java/common:semantics_bzl", + "//java/private:boot_class_path_info_bzl", + "//java/private:java_info_bzl", + "//java/private:native_bzl", + "@bazel_skylib//lib:paths", + "@rules_cc//cc/common", + ], ) filegroup( diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index aead3739..70adeccd 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -30,6 +30,13 @@ bzl_library( name = "java_helper_bzl", srcs = ["java_helper.bzl"], visibility = ["//java:__subpackages__"], + deps = [ + "//java/common:semantics_bzl", + "//java/common/rules:java_helper_bzl", + "@bazel_skylib//lib:paths", + "@rules_cc//cc:find_cc_toolchain_bzl", + "@rules_cc//cc/common", + ], ) filegroup( diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index d54c8f64..0667ee49 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Common util functions for java_* rules""" +"""Common util functions for java_* rules implementations""" load("@bazel_skylib//lib:paths.bzl", "paths") load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", _loading_phase_helper = "helper") # copybara: rules_java visibility @@ -93,7 +94,7 @@ def _primary_class(ctx): for src in ctx.files.srcs: if src.basename == main: return _full_classname(_strip_extension(src)) - return _full_classname(_get_relative(ctx.label.package, ctx.label.name)) + return _full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) def _strip_extension(file): return file.dirname + "/" + ( @@ -102,41 +103,9 @@ def _strip_extension(file): # TODO(b/193629418): once out of builtins, create a canonical implementation and remove duplicates in depot def _full_classname(path): - java_segments = _java_segments(path) + java_segments = _loading_phase_helper.java_segments(path) return ".".join(java_segments) if java_segments != None else None -def _java_segments(path): - if path.startswith("/"): - fail("path must not be absolute: '%s'" % path) - segments = path.split("/") - root_idx = -1 - for idx, segment in enumerate(segments): - if segment in ["java", "javatests", "src", "testsrc"]: - root_idx = idx - break - if root_idx < 0: - return None - is_src = "src" == segments[root_idx] - check_mvn_idx = root_idx if is_src else -1 - if (root_idx == 0 or is_src): - for i in range(root_idx + 1, len(segments) - 1): - segment = segments[i] - if "src" == segment or (is_src and (segment in ["java", "javatests"])): - next = segments[i + 1] - if next in ["com", "org", "net"]: - root_idx = i - elif "src" == segment: - check_mvn_idx = i - break - - if check_mvn_idx >= 0 and check_mvn_idx < len(segments) - 2: - next = segments[check_mvn_idx + 1] - if next in ["main", "test"]: - next = segments[check_mvn_idx + 2] - if next in ["java", "resources"]: - root_idx = check_mvn_idx + 2 - return segments[(root_idx + 1):] - def _concat(*lists): result = [] for list in lists: @@ -250,19 +219,8 @@ def _get_java_executable(ctx, java_runtime_toolchain, launcher): java_executable = ctx.workspace_name + "/" + java_executable return paths.normalize(java_executable) -def _has_target_constraints(ctx, constraints): - # Constraints is a label_list. - for constraint in constraints: - constraint_value = constraint[platform_common.ConstraintValueInfo] - if ctx.target_platform_has_constraint(constraint_value): - return True - return False - -def _is_target_platform_windows(ctx): - return _has_target_constraints(ctx, ctx.attr._windows_constraints) - def _is_absolute_target_platform_path(ctx, path): - if _is_target_platform_windows(ctx): + if helper.is_target_platform_windows(ctx): return len(path) > 2 and path[1] == ":" return path.startswith("/") @@ -274,139 +232,6 @@ def _get_test_support(ctx): return ctx.attr._test_support return None -def _resource_mapper(file): - root_relative_path = paths.relativize( - path = file.path, - start = paths.join(file.root.path, file.owner.workspace_root), - ) - return "%s:%s" % ( - file.path, - semantics.get_default_resource_path(root_relative_path, segment_extractor = _java_segments), - ) - -def _create_single_jar( - actions, - toolchain, - output, - sources = depset(), - resources = depset(), - mnemonic = "JavaSingleJar", - progress_message = "Building singlejar jar %{output}", - build_target = None, - output_creator = None): - """Register singlejar action for the output jar. - - Args: - actions: (actions) ctx.actions - toolchain: (JavaToolchainInfo) The java toolchain - output: (File) Output file of the action. - sources: (depset[File]) The jar files to merge into the output jar. - resources: (depset[File]) The files to add to the output jar. - mnemonic: (str) The action identifier - progress_message: (str) The action progress message - build_target: (Label) The target label to stamp in the manifest. Optional. - output_creator: (str) The name of the tool to stamp in the manifest. Optional, - defaults to 'singlejar' - Returns: - (File) Output file which was used for registering the action. - """ - args = actions.args() - args.set_param_file_format("shell").use_param_file("@%s", use_always = True) - args.add("--output", output) - args.add_all( - [ - "--compression", - "--normalize", - "--exclude_build_data", - "--warn_duplicate_resources", - ], - ) - args.add_all("--sources", sources) - args.add_all("--resources", resources, map_each = _resource_mapper) - - args.add("--build_target", build_target) - args.add("--output_jar_creator", output_creator) - - actions.run( - mnemonic = mnemonic, - progress_message = progress_message, - executable = toolchain.single_jar, - toolchain = semantics.JAVA_TOOLCHAIN_TYPE, - inputs = depset(transitive = [resources, sources]), - tools = [toolchain.single_jar], - outputs = [output], - arguments = [args], - use_default_shell_env = True, - ) - return output - -# TODO(hvd): use skylib shell.quote() -def _shell_escape(s): - """Shell-escape a string - - Quotes a word so that it can be used, without further quoting, as an argument - (or part of an argument) in a shell command. - - Args: - s: (str) the string to escape - - Returns: - (str) the shell-escaped string - """ - if not s: - # Empty string is a special case: needs to be quoted to ensure that it - # gets treated as a separate argument. - return "''" - for c in s.elems(): - # We do this positively so as to be sure we don't inadvertently forget - # any unsafe characters. - if not c.isalnum() and c not in "@%-_+:,./": - return "'" + s.replace("'", "'\\''") + "'" - return s - -def _detokenize_javacopts(opts): - """Detokenizes a list of options to a depset. - - Args: - opts: ([str]) the javac options to detokenize - - Returns: - (depset[str]) depset of detokenized options - """ - return depset( - [" ".join([_shell_escape(opt) for opt in opts])], - order = "preorder", - ) - -def _derive_output_file(ctx, base_file, *, name_suffix = "", extension = None, extension_suffix = ""): - """Declares a new file whose name is derived from the given file - - This method allows appending a suffix to the name (before extension), changing - the extension or appending a suffix after the extension. The new file is declared - as a sibling of the given base file. At least one of the three options must be - specified. It is an error to specify both `extension` and `extension_suffix`. - - Args: - ctx: (RuleContext) the rule context. - base_file: (File) the file from which to derive the resultant file. - name_suffix: (str) Optional. The suffix to append to the name before the - extension. - extension: (str) Optional. The new extension to use (without '.'). By default, - the base_file's extension is used. - extension_suffix: (str) Optional. The suffix to append to the base_file's extension - - Returns: - (File) the derived file - """ - if not name_suffix and not extension_suffix and not extension: - fail("At least one of name_suffix, extension or extension_suffix is required") - if extension and extension_suffix: - fail("only one of extension or extension_suffix can be specified") - if extension == None: - extension = base_file.extension - new_basename = paths.replace_extension(base_file.basename, name_suffix + "." + extension + extension_suffix) - return ctx.actions.declare_file(new_basename, sibling = base_file) - def _is_stamping_enabled(ctx, stamp): if ctx.configuration.is_tool_configuration(): return 0 @@ -416,40 +241,6 @@ def _is_stamping_enabled(ctx, stamp): # stamp == -1 / auto return int(ctx.configuration.stamp_binaries()) -def _get_relative(path_a, path_b): - if paths.is_absolute(path_b): - return path_b - return paths.normalize(paths.join(path_a, path_b)) - -def _tokenize_javacopts(ctx = None, opts = []): - """Tokenizes a list or depset of options to a list. - - Iff opts is a depset, we reverse the flattened list to ensure right-most - duplicates are preserved in their correct position. - - If the ctx parameter is omitted, a slow, but pure Starlark, implementation - of shell tokenization is used. Otherwise, tokenization is performed using - ctx.tokenize() which has significantly better performance (up to 100x for - large options lists). - - Args: - ctx: (RuleContext|None) the rule context - opts: (depset[str]|[str]) the javac options to tokenize - Returns: - [str] list of tokenized options - """ - if hasattr(opts, "to_list"): - opts = reversed(opts.to_list()) - if ctx: - return [ - token - for opt in opts - for token in ctx.tokenize(opt) - ] - else: - # TODO: optimize and use the pure Starlark implementation in cc_helper - return semantics.tokenize_javacopts(opts) - helper = struct( collect_all_targets_as_deps = _collect_all_targets_as_deps, filter_launcher_for_target = _filter_launcher_for_target, @@ -466,15 +257,14 @@ helper = struct( get_coverage_config = _get_coverage_config, get_java_executable = _get_java_executable, is_absolute_target_platform_path = _is_absolute_target_platform_path, - is_target_platform_windows = _is_target_platform_windows, + is_target_platform_windows = _loading_phase_helper.is_target_platform_windows, runfiles_enabled = _runfiles_enabled, get_test_support = _get_test_support, - create_single_jar = _create_single_jar, - shell_escape = _shell_escape, - detokenize_javacopts = _detokenize_javacopts, - tokenize_javacopts = _tokenize_javacopts, - derive_output_file = _derive_output_file, + create_single_jar = _loading_phase_helper.create_single_jar, + shell_escape = _loading_phase_helper.shell_escape, + detokenize_javacopts = _loading_phase_helper.detokenize_javacopts, + tokenize_javacopts = _loading_phase_helper.tokenize_javacopts, is_stamping_enabled = _is_stamping_enabled, - get_relative = _get_relative, - has_target_constraints = _has_target_constraints, + get_relative = _loading_phase_helper.get_relative, + has_target_constraints = _loading_phase_helper.has_target_constraints, ) diff --git a/java/common/rules/java_helper.bzl b/java/common/rules/java_helper.bzl new file mode 100644 index 00000000..ee274ade --- /dev/null +++ b/java/common/rules/java_helper.bzl @@ -0,0 +1,212 @@ +# Copyright 2025 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Common util functions for java_* rules""" + +load("@bazel_skylib//lib:paths.bzl", "paths") +load("//java/common:java_semantics.bzl", "semantics") + +# copybara: rules_java visibility + +def _java_segments(path): + if path.startswith("/"): + fail("path must not be absolute: '%s'" % path) + segments = path.split("/") + root_idx = -1 + for idx, segment in enumerate(segments): + if segment in ["java", "javatests", "src", "testsrc"]: + root_idx = idx + break + if root_idx < 0: + return None + is_src = "src" == segments[root_idx] + check_mvn_idx = root_idx if is_src else -1 + if (root_idx == 0 or is_src): + for i in range(root_idx + 1, len(segments) - 1): + segment = segments[i] + if "src" == segment or (is_src and (segment in ["java", "javatests"])): + next = segments[i + 1] + if next in ["com", "org", "net"]: + root_idx = i + elif "src" == segment: + check_mvn_idx = i + break + + if check_mvn_idx >= 0 and check_mvn_idx < len(segments) - 2: + next = segments[check_mvn_idx + 1] + if next in ["main", "test"]: + next = segments[check_mvn_idx + 2] + if next in ["java", "resources"]: + root_idx = check_mvn_idx + 2 + return segments[(root_idx + 1):] + +def _has_target_constraints(ctx, constraints): + # Constraints is a label_list. + for constraint in constraints: + constraint_value = constraint[platform_common.ConstraintValueInfo] + if ctx.target_platform_has_constraint(constraint_value): + return True + return False + +def _is_target_platform_windows(ctx): + return _has_target_constraints(ctx, ctx.attr._windows_constraints) + +def _resource_mapper(file): + root_relative_path = paths.relativize( + path = file.path, + start = paths.join(file.root.path, file.owner.workspace_root), + ) + return "%s:%s" % ( + file.path, + semantics.get_default_resource_path(root_relative_path, segment_extractor = _java_segments), + ) + +def _create_single_jar( + actions, + toolchain, + output, + sources = depset(), + resources = depset(), + mnemonic = "JavaSingleJar", + progress_message = "Building singlejar jar %{output}", + build_target = None, + output_creator = None): + """Register singlejar action for the output jar. + + Args: + actions: (actions) ctx.actions + toolchain: (JavaToolchainInfo) The java toolchain + output: (File) Output file of the action. + sources: (depset[File]) The jar files to merge into the output jar. + resources: (depset[File]) The files to add to the output jar. + mnemonic: (str) The action identifier + progress_message: (str) The action progress message + build_target: (Label) The target label to stamp in the manifest. Optional. + output_creator: (str) The name of the tool to stamp in the manifest. Optional, + defaults to 'singlejar' + Returns: + (File) Output file which was used for registering the action. + """ + args = actions.args() + args.set_param_file_format("shell").use_param_file("@%s", use_always = True) + args.add("--output", output) + args.add_all( + [ + "--compression", + "--normalize", + "--exclude_build_data", + "--warn_duplicate_resources", + ], + ) + args.add_all("--sources", sources) + args.add_all("--resources", resources, map_each = _resource_mapper) + + args.add("--build_target", build_target) + args.add("--output_jar_creator", output_creator) + + actions.run( + mnemonic = mnemonic, + progress_message = progress_message, + executable = toolchain.single_jar, + toolchain = semantics.JAVA_TOOLCHAIN_TYPE, + inputs = depset(transitive = [resources, sources]), + tools = [toolchain.single_jar], + outputs = [output], + arguments = [args], + use_default_shell_env = True, + ) + return output + +# TODO(hvd): use skylib shell.quote() +def _shell_escape(s): + """Shell-escape a string + + Quotes a word so that it can be used, without further quoting, as an argument + (or part of an argument) in a shell command. + + Args: + s: (str) the string to escape + + Returns: + (str) the shell-escaped string + """ + if not s: + # Empty string is a special case: needs to be quoted to ensure that it + # gets treated as a separate argument. + return "''" + for c in s.elems(): + # We do this positively so as to be sure we don't inadvertently forget + # any unsafe characters. + if not c.isalnum() and c not in "@%-_+:,./": + return "'" + s.replace("'", "'\\''") + "'" + return s + +def _detokenize_javacopts(opts): + """Detokenizes a list of options to a depset. + + Args: + opts: ([str]) the javac options to detokenize + + Returns: + (depset[str]) depset of detokenized options + """ + return depset( + [" ".join([_shell_escape(opt) for opt in opts])], + order = "preorder", + ) + +def _get_relative(path_a, path_b): + if paths.is_absolute(path_b): + return path_b + return paths.normalize(paths.join(path_a, path_b)) + +def _tokenize_javacopts(ctx = None, opts = []): + """Tokenizes a list or depset of options to a list. + + Iff opts is a depset, we reverse the flattened list to ensure right-most + duplicates are preserved in their correct position. + + If the ctx parameter is omitted, a slow, but pure Starlark, implementation + of shell tokenization is used. Otherwise, tokenization is performed using + ctx.tokenize() which has significantly better performance (up to 100x for + large options lists). + + Args: + ctx: (RuleContext|None) the rule context + opts: (depset[str]|[str]) the javac options to tokenize + Returns: + [str] list of tokenized options + """ + if hasattr(opts, "to_list"): + opts = reversed(opts.to_list()) + if ctx: + return [ + token + for opt in opts + for token in ctx.tokenize(opt) + ] + else: + # TODO: optimize and use the pure Starlark implementation in cc_helper + return semantics.tokenize_javacopts(opts) + +helper = struct( + is_target_platform_windows = _is_target_platform_windows, + create_single_jar = _create_single_jar, + shell_escape = _shell_escape, + detokenize_javacopts = _detokenize_javacopts, + tokenize_javacopts = _tokenize_javacopts, + get_relative = _get_relative, + has_target_constraints = _has_target_constraints, + java_segments = _java_segments, +) diff --git a/java/common/rules/java_package_configuration.bzl b/java/common/rules/java_package_configuration.bzl index 2c24b450..e6b1885f 100644 --- a/java/common/rules/java_package_configuration.bzl +++ b/java/common/rules/java_package_configuration.bzl @@ -14,7 +14,7 @@ """Implementation for the java_package_configuration rule""" -load("//java/common/rules/impl:java_helper.bzl", "helper") +load("//java/common/rules:java_helper.bzl", "helper") load("//java/private:boot_class_path_info.bzl", "BootClassPathInfo") load("//java/private:native.bzl", "get_internal_java_common") diff --git a/java/common/rules/java_runtime.bzl b/java/common/rules/java_runtime.bzl index 47a93435..2433549c 100644 --- a/java/common/rules/java_runtime.bzl +++ b/java/common/rules/java_runtime.bzl @@ -19,7 +19,7 @@ Definition of java_runtime rule and JavaRuntimeInfo provider. load("@bazel_skylib//lib:paths.bzl", "paths") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("//java/common:java_semantics.bzl", "semantics") -load("//java/common/rules/impl:java_helper.bzl", "helper") +load("//java/common/rules:java_helper.bzl", "helper") # copybara: default visibility diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index 6aed2ecd..d08775a5 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -17,7 +17,7 @@ Definition of java_toolchain rule and JavaToolchainInfo provider. """ load("//java/common:java_semantics.bzl", "semantics") -load("//java/common/rules/impl:java_helper.bzl", "helper") +load("//java/common/rules:java_helper.bzl", "helper") load("//java/private:boot_class_path_info.bzl", "BootClassPathInfo") load("//java/private:java_info.bzl", "JavaPluginDataInfo") load("//java/private:native.bzl", "get_internal_java_common") diff --git a/java/private/BUILD b/java/private/BUILD index bbed12b8..510c3010 100644 --- a/java/private/BUILD +++ b/java/private/BUILD @@ -23,10 +23,8 @@ bzl_library( bzl_library( name = "internals", srcs = [ - "boot_class_path_info.bzl", "java_common.bzl", "java_common_internal.bzl", - "java_info.bzl", "message_bundle_info.bzl", ], visibility = [ @@ -34,9 +32,12 @@ bzl_library( "@compatibility_proxy//:__pkg__", ], deps = [ + ":boot_class_path_info_bzl", + ":java_info_bzl", ":native_bzl", + "//java/common:semantics_bzl", + "//java/common/rules:java_helper_bzl", "//java/common/rules:toolchain_rules", - "//java/common/rules/impl:java_helper_bzl", "@bazel_skylib//lib:paths", "@bazel_skylib//rules:common_settings", "@rules_cc//cc:find_cc_toolchain_bzl", @@ -44,6 +45,24 @@ bzl_library( ], ) +bzl_library( + name = "boot_class_path_info_bzl", + srcs = ["boot_class_path_info.bzl"], + visibility = ["//java:__subpackages__"], + deps = ["@bazel_skylib//lib:paths"], +) + +bzl_library( + name = "java_info_bzl", + srcs = ["java_info.bzl"], + visibility = ["//java:__subpackages__"], + deps = [ + ":native_bzl", + "//java/common:semantics_bzl", + "@rules_cc//cc/common", + ], +) + # Exposed for use by the protobuf. bzl_library( name = "proto_support", diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 70461632..8a465c26 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl @@ -16,9 +16,9 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") load("//java/common/rules:java_runtime.bzl", "JavaRuntimeInfo") load("//java/common/rules:java_toolchain.bzl", "JavaToolchainInfo") -load("//java/common/rules/impl:java_helper.bzl", "helper") load(":boot_class_path_info.bzl", "BootClassPathInfo") load( ":java_common_internal.bzl", diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl index 7af3bf79..249b9255 100644 --- a/java/private/java_common_internal.bzl +++ b/java/private/java_common_internal.bzl @@ -16,8 +16,8 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") load("//java/common/rules:java_toolchain.bzl", "JavaToolchainInfo") -load("//java/common/rules/impl:java_helper.bzl", "helper") load( ":java_info.bzl", "JavaPluginInfo", @@ -222,14 +222,14 @@ def compile( header_compilation_jar = compile_jar compile_deps_proto = None elif _should_use_header_compilation(ctx, java_toolchain): - compile_jar = helper.derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jar") + compile_jar = _derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jar") # TODO: b/417791104 - remove check after a Bazel release if ctx.fragments.java.use_header_compilation_direct_deps(): - header_compilation_jar = helper.derive_output_file(ctx, output, name_suffix = "-tjar", extension = "jar") + header_compilation_jar = _derive_output_file(ctx, output, name_suffix = "-tjar", extension = "jar") else: header_compilation_jar = None - compile_deps_proto = helper.derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jdeps") + compile_deps_proto = _derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jdeps") get_internal_java_common().create_header_compilation_action( ctx, java_toolchain, @@ -266,16 +266,16 @@ def compile( header_compilation_jar = compile_jar compile_deps_proto = None - native_headers_jar = helper.derive_output_file(ctx, output, name_suffix = "-native-header") - manifest_proto = helper.derive_output_file(ctx, output, extension_suffix = "_manifest_proto") + native_headers_jar = _derive_output_file(ctx, output, name_suffix = "-native-header") + manifest_proto = _derive_output_file(ctx, output, extension_suffix = "_manifest_proto") deps_proto = None if ctx.fragments.java.generate_java_deps() and has_sources: - deps_proto = helper.derive_output_file(ctx, output, extension = "jdeps") + deps_proto = _derive_output_file(ctx, output, extension = "jdeps") generated_class_jar = None generated_source_jar = None if uses_annotation_processing: - generated_class_jar = helper.derive_output_file(ctx, output, name_suffix = "-gen") - generated_source_jar = helper.derive_output_file(ctx, output, name_suffix = "-gensrc") + generated_class_jar = _derive_output_file(ctx, output, name_suffix = "-gen") + generated_source_jar = _derive_output_file(ctx, output, name_suffix = "-gensrc") get_internal_java_common().create_compilation_action( ctx, java_toolchain, @@ -309,7 +309,7 @@ def compile( create_output_source_jar = len(source_files) > 0 or source_jars != [output_source_jar] if not output_source_jar: - output_source_jar = helper.derive_output_file(ctx, output, name_suffix = "-src", extension = "jar") + output_source_jar = _derive_output_file(ctx, output, name_suffix = "-src", extension = "jar") if create_output_source_jar: helper.create_single_jar( ctx.actions, @@ -364,6 +364,35 @@ def compile( compilation_info = compilation_info, ) +def _derive_output_file(ctx, base_file, *, name_suffix = "", extension = None, extension_suffix = ""): + """Declares a new file whose name is derived from the given file + + This method allows appending a suffix to the name (before extension), changing + the extension or appending a suffix after the extension. The new file is declared + as a sibling of the given base file. At least one of the three options must be + specified. It is an error to specify both `extension` and `extension_suffix`. + + Args: + ctx: (RuleContext) the rule context. + base_file: (File) the file from which to derive the resultant file. + name_suffix: (str) Optional. The suffix to append to the name before the + extension. + extension: (str) Optional. The new extension to use (without '.'). By default, + the base_file's extension is used. + extension_suffix: (str) Optional. The suffix to append to the base_file's extension + + Returns: + (File) the derived file + """ + if not name_suffix and not extension_suffix and not extension: + fail("At least one of name_suffix, extension or extension_suffix is required") + if extension and extension_suffix: + fail("only one of extension or extension_suffix can be specified") + if extension == None: + extension = base_file.extension + new_basename = paths.replace_extension(base_file.basename, name_suffix + "." + extension + extension_suffix) + return ctx.actions.declare_file(new_basename, sibling = base_file) + def _should_use_header_compilation(ctx, toolchain): if not ctx.fragments.java.use_header_compilation(): return False From 113827798fc6ddcd180ebe365b8b4951eb628def Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 1 Dec 2025 05:28:38 -0800 Subject: [PATCH 065/251] Internal change (ignore-relnotes) PiperOrigin-RevId: 838728638 Change-Id: I9973ebcaba675627ba2f9f6ce3a74139560cbe12 --- java/common/rules/impl/java_helper.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 0667ee49..efc7f0e5 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -101,7 +101,7 @@ def _strip_extension(file): file.basename[:-(1 + len(file.extension))] if file.extension else file.basename ) -# TODO(b/193629418): once out of builtins, create a canonical implementation and remove duplicates in depot +# TODO(b/465048589): once out of builtins, create a canonical implementation and remove duplicates in depot def _full_classname(path): java_segments = _loading_phase_helper.java_segments(path) return ".".join(java_segments) if java_segments != None else None From 686ed85f30ae22018327552d5d2d9a4f8486d772 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 2 Dec 2025 00:42:13 -0800 Subject: [PATCH 066/251] Update to `java_tools` `v18.0` https://github.com/bazelbuild/bazel/issues/27810 PiperOrigin-RevId: 839131461 Change-Id: I1ef7b762aac490c5b509e91519d65f4d11a70825 --- java/repositories.bzl | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/java/repositories.bzl b/java/repositories.bzl index 82093756..1e336502 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,38 +22,38 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v17.0", + "version": "v18.0", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_linux-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_linux-v17.0.zip", - "sha": "5f89d5d04b41dbe1d661836b6a76c468113e0080953bcd72aaf6711c7462b86a", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_linux-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_linux-v18.0.zip", + "sha": "f0b49f6fa369f581b1194a91feb55ef8bf99683c7e76867854b6372782772f00", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_linux_aarch64-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_linux_aarch64-v17.0.zip", - "sha": "c36a17057e895b260cb8f2f7961ed7480812ab6923dab5a39f0c93263e2f76f2", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_linux_aarch64-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_linux_aarch64-v18.0.zip", + "sha": "8f8a436c858e39ae9f40b54a3515e0c6b5c3f9e8f0ae9ae13b968c314e7cf7f0", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_windows-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_windows-v17.0.zip", - "sha": "3ae5075b228ce464c74bd23602a65016f662895556fa8952cba2995d50904c86", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_windows-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_windows-v18.0.zip", + "sha": "66016d0c56c8f2d3f63e1076ae2b4baa598c5f51e531998336af112d4f3c72d0", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_darwin_x86_64-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_darwin_x86_64-v17.0.zip", - "sha": "c65a181af0e723ed1a36c494aa0f70753f128adb7655a7b57f8f7e71217ad35c", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_darwin_x86_64-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_darwin_x86_64-v18.0.zip", + "sha": "843b393d4a7ece1baea0d3611c6fe997d5326c36bd743501bd472a7d1e808edd", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools_darwin_arm64-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools_darwin_arm64-v17.0.zip", - "sha": "00787917e359e2218953dbc30e228670e83fa20c4a0a5f914e0b6ecdee85fa9d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_darwin_arm64-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_darwin_arm64-v18.0.zip", + "sha": "657ecf25c4a8119a9e73a04a4f4f4e357250e68adbf83a77327053705877dd4f", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v17.0/java_tools-v17.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v17.0/java_tools-v17.0.zip", - "sha": "9a441ca2d4ae393edd305b0e465b0ed8ee86b22123c41c26455fb856bf9bc897", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools-v18.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools-v18.0.zip", + "sha": "75a5d083a72782ea66806ee447729d1ab24b6100303da6e7985fcadae5c62533", }, }, } From dbd8cb408911b79c6d7047ac4355ff89b1b90685 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 2 Dec 2025 00:50:55 -0800 Subject: [PATCH 067/251] Release `rules_java` `v9.2.0` PiperOrigin-RevId: 839134114 Change-Id: Ic149bcc8ca9b8b7e96305330716483d7f3a6a54a --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 24653fe2..527f5bf9 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.1.0", + version = "9.2.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 20951906fa6a74346663acc39a6fd22378128cb6 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 3 Dec 2025 06:08:39 -0800 Subject: [PATCH 068/251] Refer to the SingleJar "executable" instead of "deploy jar." I don't think it's been a deploy jar in any environment for a while, and whatever it is, I think we run it directly as a executable. PiperOrigin-RevId: 839725877 Change-Id: I8d8e67b3eb7bd4af11387efb727853740370f565 --- java/common/rules/java_toolchain.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index d08775a5..a24ae4f1 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -43,7 +43,7 @@ JavaToolchainInfo, _new_javatoolchaininfo = provider( "jvm_opt": "(depset[str]) The default options for the JVM running the java compiler and associated tools.", "label": "(label) The toolchain label.", "proguard_allowlister": "(FilesToRunProvider) The binary to validate proguard configuration.", - "single_jar": "(FilesToRunProvider) The SingleJar deploy jar.", + "single_jar": "(FilesToRunProvider) The SingleJar executable.", "source_version": "(str) The java source version.", "target_version": "(str) The java target version.", "tools": "(depset[File]) The compilation tools.", @@ -546,7 +546,7 @@ Label of the Proguard allowlister. allow_files = True, executable = True, doc = """ -Label of the SingleJar deploy jar. +Label of the SingleJar executable. """, ), "source_version": attr.string( From 14562f01110b7fb272625abe8250d438a7855993 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 3 Dec 2025 12:03:02 -0800 Subject: [PATCH 069/251] Support --library boolean flag for Android Lint in Java rules PiperOrigin-RevId: 839855551 Change-Id: I7d28e22b9fed9c8cd9f64bceb1081ac9fa8f97ab --- java/common/rules/android_lint.bzl | 4 +++- java/common/rules/impl/basic_java_library_impl.bzl | 5 ++++- java/common/rules/impl/java_binary_impl.bzl | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/java/common/rules/android_lint.bzl b/java/common/rules/android_lint.bzl index f0a04328..032e06bc 100644 --- a/java/common/rules/android_lint.bzl +++ b/java/common/rules/android_lint.bzl @@ -22,7 +22,7 @@ def _tokenize_opts(opts_depset): opts = reversed(opts_depset.to_list()) return semantics.tokenize_javacopts(opts) -def _android_lint_action(ctx, source_files, source_jars, compilation_info): +def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_library): """ Creates an action that runs Android lint against Java source files. @@ -42,6 +42,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info): source_jars: (list[File]) A list of .jar or .srcjar files containing source files. It should also include generated source jars. compilation_info: (struct) Information about compilation. + is_library: (bool) Whether the target is a library. Returns: (None|File) The Android lint output file or None if no source files were @@ -101,6 +102,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info): args.add_all("--classpath", classpath) args.add_all("--lint_rules", compilation_info.plugins.processor_jars) args.add("--target_label", ctx.label) + args.add("--library", str(is_library).lower()) javac_opts = compilation_info.javac_options if javac_opts: diff --git a/java/common/rules/impl/basic_java_library_impl.bzl b/java/common/rules/impl/basic_java_library_impl.bzl index cf7c5c19..a0105794 100644 --- a/java/common/rules/impl/basic_java_library_impl.bzl +++ b/java/common/rules/impl/basic_java_library_impl.bzl @@ -71,7 +71,8 @@ def basic_java_library( add_exports = [], add_opens = [], bootclasspath = None, - javabuilder_jvm_flags = None): + javabuilder_jvm_flags = None, + is_library = True): """ Creates actions that compile and lint Java sources, sets up coverage and returns JavaInfo, InstrumentedFilesInfo and output groups. @@ -107,6 +108,7 @@ def basic_java_library( add_opens: (list[str]) Allow this library to reflectively access the given /. bootclasspath: (Target) The JDK APIs to compile this library against. javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder. + is_library: (bool) Whether the target is a library. Primarily for static analysis purposes. Returns: (dict[str, Provider], {files_to_build: list[File], @@ -168,6 +170,7 @@ def basic_java_library( source_files, source_jars + generated_source_jars, compilation_info, + is_library, ) if lint_output: validation_outputs.append(depset([lint_output])) diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 50dcaae9..8b9b68de 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -118,6 +118,7 @@ def basic_java_binary( add_exports = ctx.attr.add_exports, add_opens = ctx.attr.add_opens, bootclasspath = ctx.attr.bootclasspath, + is_library = False, ) java_info = target["JavaInfo"] compilation_info = java_info.compilation_info From e6ba46c4e3b70797b164713ca1c01a7e25c44fa9 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 4 Dec 2025 03:09:54 -0800 Subject: [PATCH 070/251] Internal change (ignore-relnotes) PiperOrigin-RevId: 840160023 Change-Id: I0d0e965fca4bfce972b6b2fde504a4132e692f9e --- java/private/legacy_native.bzl | 2 ++ java/private/native.bzl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/java/private/legacy_native.bzl b/java/private/legacy_native.bzl index 7a9e62fc..770434bc 100644 --- a/java/private/legacy_native.bzl +++ b/java/private/legacy_native.bzl @@ -17,6 +17,8 @@ """Lovely workaround to be able to expose native constants pretending to be Starlark.""" +# copybara: default visibility + # Unused with Bazel@HEAD, only used by the compatibility layer for older Bazel versions # buildifier: disable=native-java-common diff --git a/java/private/native.bzl b/java/private/native.bzl index be7ae686..cd45aa7a 100644 --- a/java/private/native.bzl +++ b/java/private/native.bzl @@ -14,6 +14,8 @@ """Redirects for private native APIs""" +# copybara: default visibility + # Used for some private native APIs that we can't replicate just yet in Starlark def get_internal_java_common(): return java_common.internal_DO_NOT_USE() # buildifier: disable=native-java-common From 92f148693341f6f7e10667af5f02a6829eda235b Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 9 Dec 2025 07:36:00 -0800 Subject: [PATCH 071/251] Update to `java_tools` `18.1` For https://github.com/bazelbuild/bazel/issues/27862 PiperOrigin-RevId: 842231974 Change-Id: I77d2196e6d5b595c9dd93344f2982e06423b0dc4 --- java/repositories.bzl | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/java/repositories.bzl b/java/repositories.bzl index 1e336502..5b1f317e 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,38 +22,38 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v18.0", + "version": "v18.1", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_linux-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_linux-v18.0.zip", - "sha": "f0b49f6fa369f581b1194a91feb55ef8bf99683c7e76867854b6372782772f00", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_linux-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_linux-v18.1.zip", + "sha": "e22cbb2600249576c6a0a02af3f78e26537a89b6be11ef3826c01f9019faaa61", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_linux_aarch64-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_linux_aarch64-v18.0.zip", - "sha": "8f8a436c858e39ae9f40b54a3515e0c6b5c3f9e8f0ae9ae13b968c314e7cf7f0", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_linux_aarch64-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_linux_aarch64-v18.1.zip", + "sha": "4f75420bafb8c6554105c90ed05db3d7ff5942dbc1633459c20d2dcc06eff6ac", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_windows-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_windows-v18.0.zip", - "sha": "66016d0c56c8f2d3f63e1076ae2b4baa598c5f51e531998336af112d4f3c72d0", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_windows-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_windows-v18.1.zip", + "sha": "fe6dccef1b290b9e2a539cecfd57d924f719480ac04e55d03fdca5533272cd04", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_darwin_x86_64-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_darwin_x86_64-v18.0.zip", - "sha": "843b393d4a7ece1baea0d3611c6fe997d5326c36bd743501bd472a7d1e808edd", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_darwin_x86_64-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_darwin_x86_64-v18.1.zip", + "sha": "68f6b540a28ff1d98acd9313900c50560d52022ee2399627b9c92b1bb2c5d466", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools_darwin_arm64-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools_darwin_arm64-v18.0.zip", - "sha": "657ecf25c4a8119a9e73a04a4f4f4e357250e68adbf83a77327053705877dd4f", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_darwin_arm64-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_darwin_arm64-v18.1.zip", + "sha": "07026303be4662462733d00eaf8e956cd9589493e104934862f0b53e76758d88", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.0/java_tools-v18.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.0/java_tools-v18.0.zip", - "sha": "75a5d083a72782ea66806ee447729d1ab24b6100303da6e7985fcadae5c62533", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools-v18.1.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools-v18.1.zip", + "sha": "27cab59ba5ff8ee7cf3071971fe2587a295daefe82531f27b4f061111276163d", }, }, } From 9d6184b9f6979fe5680f8b99173656a45aea53e8 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 9 Dec 2025 07:42:11 -0800 Subject: [PATCH 072/251] Release `rules_java` `9.3.0` PiperOrigin-RevId: 842233855 Change-Id: Ifd52f02586754a8543cfab84469bc54ebc749be3 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 527f5bf9..23ee0cee 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.2.0", + version = "9.3.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 59e9cb58e40b54035e58a1b373ee207b10912e63 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 19 Dec 2025 06:41:58 -0800 Subject: [PATCH 073/251] Automatic code cleanup. PiperOrigin-RevId: 846713425 Change-Id: Id0e2b980fc4082582556de3084d1ddd0316fc7cd --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 2761f404..9f0e2239 100644 --- a/BUILD +++ b/BUILD @@ -1,6 +1,6 @@ load("@rules_license//rules:license.bzl", "license") -package(default_applicable_licenses = ["@rules_java//:license"]) +package(default_applicable_licenses = [":license"]) licenses(["notice"]) From aa0345c749ae24b4ff3e9ca92e52bbcd96bc135a Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 5 Jan 2026 08:21:14 -0800 Subject: [PATCH 074/251] Instruct `java_binary` not to compress `protobuf.meta`. Compressing the file accounts for a noticeable fraction of runtime. This CL has no effect until after a JavaBuilder that contains unknown commit. PiperOrigin-RevId: 852309989 Change-Id: I255419359afb4f0fee0ffcf7a233f385c8d81b53 --- java/common/rules/impl/java_binary_deploy_jar.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index 8755d959..7b7d69d1 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -182,6 +182,7 @@ def create_deploy_archive( args.add("--build_target", build_target) args.add("--normalize") args.add("--compression") + args.add("--nocompress_suffixes", "protobuf.meta") if main_class: args.add("--main_class", main_class) args.add_all("--deploy_manifest_lines", manifest_lines) From 624b2083103705e583ea4a17a7f3f902aa921412 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 8 Jan 2026 09:09:41 -0800 Subject: [PATCH 075/251] avoid loading from defs.bzl (#341) At least the example should use the preferred load paths. Closes #341 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/341 from benjaminp:no-defs 479d18ebcdf74770ffa0c4573d56d5c9399212d3 PiperOrigin-RevId: 853768220 Change-Id: Iee1770d77675a9bfb371894aaac0ac6b67320d09 --- examples/hello_world/BUILD | 2 +- .../src/main/java/com/google/devtools/build/runfiles/BUILD | 3 ++- test/java/private/android_support_tests.bzl | 3 ++- .../testutil/rules/custom_library_with_wrong_plugins_type.bzl | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/hello_world/BUILD b/examples/hello_world/BUILD index 2e951cc2..f8ee9577 100644 --- a/examples/hello_world/BUILD +++ b/examples/hello_world/BUILD @@ -1,4 +1,4 @@ -load("//java:defs.bzl", "java_binary") +load("//java:java_binary.bzl", "java_binary") package(default_applicable_licenses = ["@rules_java//:license"]) diff --git a/java/runfiles/src/main/java/com/google/devtools/build/runfiles/BUILD b/java/runfiles/src/main/java/com/google/devtools/build/runfiles/BUILD index 5b521a9b..11b8ae0f 100644 --- a/java/runfiles/src/main/java/com/google/devtools/build/runfiles/BUILD +++ b/java/runfiles/src/main/java/com/google/devtools/build/runfiles/BUILD @@ -1,4 +1,5 @@ -load("//java:defs.bzl", "java_library", "java_plugin") +load("//java:java_library.bzl", "java_library") +load("//java:java_plugin.bzl", "java_plugin") package(default_applicable_licenses = ["@rules_java//:license"]) diff --git a/test/java/private/android_support_tests.bzl b/test/java/private/android_support_tests.bzl index 95596de2..8f9bea64 100644 --- a/test/java/private/android_support_tests.bzl +++ b/test/java/private/android_support_tests.bzl @@ -15,7 +15,8 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") -load("//java:defs.bzl", "java_library", "java_plugin") +load("//java:java_library.bzl", "java_library") +load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_info.bzl", "JavaInfo") load("//java/private:android_support.bzl", "android_support") # buildifier: disable=bzl-visibility load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") diff --git a/test/java/testutil/rules/custom_library_with_wrong_plugins_type.bzl b/test/java/testutil/rules/custom_library_with_wrong_plugins_type.bzl index 12535307..dc58cee1 100644 --- a/test/java/testutil/rules/custom_library_with_wrong_plugins_type.bzl +++ b/test/java/testutil/rules/custom_library_with_wrong_plugins_type.bzl @@ -1,6 +1,7 @@ """Custom rule to test java_common.compile(plugins = ...) expects JavaPluginInfo""" -load("//java:defs.bzl", "JavaInfo", "java_common") +load("//java/common:java_common.bzl", "java_common") +load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") def _impl(ctx): From e0bcbba9d24771be7b885676298e14ce3058d84d Mon Sep 17 00:00:00 2001 From: hvadehra Date: Fri, 30 Jan 2026 01:29:53 -0800 Subject: [PATCH 076/251] Fix javacopts make variable expansion regression (#346) Looks like this was a regression introduced when we Starlarkified the rules. Unfortunately, we apparently had no test coverage for this, and no usages internally either. No one has complained about it since either - until now. Fixes https://github.com/bazelbuild/rules_java/issues/345 Closes #346 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/346 from bazelbuild:hvd_i345 524df33e55cf73e76dea4d21fe9d0dda418621f2 PiperOrigin-RevId: 863121793 Change-Id: I50c393f85a5117401bd470b85ee62108d9f0a5fe --- java/common/java_semantics.bzl | 1 + java/common/rules/impl/compile_action.bzl | 7 ++- test/java/bazel/rules/BUILD.bazel | 6 +++ test/java/bazel/rules/java_binary_tests.bzl | 32 ++++++++++++++ test/java/bazel/rules/java_library_tests.bzl | 44 +++++++++++++++++++ test/java/bazel/rules/java_plugin_tests.bzl | 43 ++++++++++++++++++ .../testutil/rules/template_var_info_rule.bzl | 13 ++++++ 7 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 test/java/bazel/rules/java_library_tests.bzl create mode 100644 test/java/bazel/rules/java_plugin_tests.bzl create mode 100644 test/java/testutil/rules/template_var_info_rule.bzl diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 700c0d1d..31c0a006 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -113,4 +113,5 @@ semantics = struct( tokenize_javacopts = _tokenize_javacopts, PLATFORMS_ROOT = "@platforms//", INCOMPATIBLE_DISABLE_NON_EXECUTABLE_JAVA_BINARY = False, # Flip when java_single_jar is feature complete + expand_javacopts_make_variables = True, ) diff --git a/java/common/rules/impl/compile_action.bzl b/java/common/rules/impl/compile_action.bzl index bf5b9359..098c55bb 100644 --- a/java/common/rules/impl/compile_action.bzl +++ b/java/common/rules/impl/compile_action.bzl @@ -135,7 +135,10 @@ def compile_action( Files_to_build may include an empty .jar file when there are no sources or resources present, whereas runfiles in this case are empty. """ - + expanded_javacopts = javacopts + if semantics.expand_javacopts_make_variables: + expanded_javacopts = [ctx.expand_make_variables("javacopts", opt, {}) for opt in expanded_javacopts] + expanded_javacopts = [ctx.expand_location(opt) for opt in expanded_javacopts] java_info = _compile_private_for_builtins( ctx, output = output_class_jar, @@ -151,7 +154,7 @@ def compile_action( runtime_deps = runtime_deps, exports = exports, exported_plugins = exported_plugins, - javac_opts = [ctx.expand_location(opt) for opt in javacopts], + javac_opts = expanded_javacopts, neverlink = neverlink, output_source_jar = output_source_jar, strict_deps = _filter_strict_deps(strict_deps), diff --git a/test/java/bazel/rules/BUILD.bazel b/test/java/bazel/rules/BUILD.bazel index 3bf8f436..01655c20 100644 --- a/test/java/bazel/rules/BUILD.bazel +++ b/test/java/bazel/rules/BUILD.bazel @@ -1,3 +1,9 @@ load(":java_binary_tests.bzl", "java_binary_tests") +load(":java_library_tests.bzl", "java_library_tests") +load(":java_plugin_tests.bzl", "java_plugin_tests") java_binary_tests(name = "java_binary_tests") + +java_library_tests(name = "java_library_tests") + +java_plugin_tests(name = "java_plugin_tests") diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 32036d82..2d015b67 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -3,6 +3,8 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:rules/template_var_info_rule.bzl", "template_var_info_rule") def _test_java_binary_cross_compilation_to_unix(name): # A Unix platform that: @@ -46,10 +48,40 @@ def _test_java_binary_cross_compilation_to_unix_impl(env, target): assert_action.substitutions().keys().contains("%jvm_flags%") assert_action.inputs().contains_exactly(["java/bazel/rules/java_stub_template.txt"]) +def _test_java_binary_javacopts_make_variable_expansion(name): + util.helper_target( + template_var_info_rule, + name = name + "/vars", + vars = { + "MY_CUSTOM_OPT": "MY_OPT_VALUE", + }, + ) + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["java/A.java"], + javacopts = ["$(MY_CUSTOM_OPT)"], + toolchains = [name + "/vars"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_javacopts_make_variable_expansion_impl, + target = name + "/bin", + # Broken by Starlarkification in the embedded rules in Bazel 7 + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_binary_javacopts_make_variable_expansion_impl(env, target): + assert_java_info = java_info_subject.from_target(env, target) + assert_java_info.compilation_info().javac_options().not_contains("$(MY_CUSTOM_OPT)") + assert_java_info.compilation_info().javac_options().contains("MY_OPT_VALUE") + def java_binary_tests(name): test_suite( name = name, tests = [ _test_java_binary_cross_compilation_to_unix, + _test_java_binary_javacopts_make_variable_expansion, ], ) diff --git a/test/java/bazel/rules/java_library_tests.bzl b/test/java/bazel/rules/java_library_tests.bzl new file mode 100644 index 00000000..770fbe60 --- /dev/null +++ b/test/java/bazel/rules/java_library_tests.bzl @@ -0,0 +1,44 @@ +"""Tests for the Bazel java_binary rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:rules/template_var_info_rule.bzl", "template_var_info_rule") + +def _test_java_library_javacopts_make_variable_expansion(name): + util.helper_target( + template_var_info_rule, + name = name + "/vars", + vars = { + "MY_CUSTOM_OPT": "MY_OPT_VALUE", + }, + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["java/A.java"], + javacopts = ["$(MY_CUSTOM_OPT)"], + toolchains = [name + "/vars"], + ) + + analysis_test( + name = name, + impl = _test_java_library_javacopts_make_variable_expansion_impl, + target = name + "/lib", + # Broken by Starlarkification in the embedded rules in Bazel 7 + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_library_javacopts_make_variable_expansion_impl(env, target): + assert_java_info = java_info_subject.from_target(env, target) + assert_java_info.compilation_info().javac_options().not_contains("$(MY_CUSTOM_OPT)") + assert_java_info.compilation_info().javac_options().contains("MY_OPT_VALUE") + +def java_library_tests(name): + test_suite( + name = name, + tests = [ + _test_java_library_javacopts_make_variable_expansion, + ], + ) diff --git a/test/java/bazel/rules/java_plugin_tests.bzl b/test/java/bazel/rules/java_plugin_tests.bzl new file mode 100644 index 00000000..4df4bcca --- /dev/null +++ b/test/java/bazel/rules/java_plugin_tests.bzl @@ -0,0 +1,43 @@ +"""Tests for the Bazel java_binary rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_plugin.bzl", "java_plugin") +load("//test/java/testutil:rules/template_var_info_rule.bzl", "template_var_info_rule") + +def _test_java_plugin_javacopts_make_variable_expansion(name): + util.helper_target( + template_var_info_rule, + name = name + "/vars", + vars = { + "MY_CUSTOM_OPT": "MY_OPT_VALUE", + }, + ) + util.helper_target( + java_plugin, + name = name + "/plug", + srcs = ["java/A.java"], + javacopts = ["$(MY_CUSTOM_OPT)"], + toolchains = [name + "/vars"], + ) + + analysis_test( + name = name, + impl = _test_java_plugin_javacopts_make_variable_expansion_impl, + target = name + "/plug", + # Broken by Starlarkification in the embedded rules in Bazel 7 + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_plugin_javacopts_make_variable_expansion_impl(env, target): + assert_javac = env.expect.that_target(target).action_named("Javac") + assert_javac.not_contains_arg("$(MY_CUSTOM_OPT)") + assert_javac.contains_at_least_args(["MY_OPT_VALUE"]) + +def java_plugin_tests(name): + test_suite( + name = name, + tests = [ + _test_java_plugin_javacopts_make_variable_expansion, + ], + ) diff --git a/test/java/testutil/rules/template_var_info_rule.bzl b/test/java/testutil/rules/template_var_info_rule.bzl new file mode 100644 index 00000000..ebdc86cc --- /dev/null +++ b/test/java/testutil/rules/template_var_info_rule.bzl @@ -0,0 +1,13 @@ +"""Test rule to provide TemplateVariableInfo""" + +def _template_var_info_rule_impl(ctx): + return [ + platform_common.TemplateVariableInfo(ctx.attr.vars), + ] + +template_var_info_rule = rule( + _template_var_info_rule_impl, + attrs = { + "vars": attr.string_dict(default = {}), + }, +) From e910554011ae22d697ccf371d3f38f56b0721516 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 30 Jan 2026 03:00:28 -0800 Subject: [PATCH 077/251] Fix `@rules_java` CI after https://github.com/bazelbuild/buildtools/releases/tag/v8.5.1 Broken by https://github.com/bazelbuild/buildtools/pull/1386 PiperOrigin-RevId: 863149692 Change-Id: I81ca12ed891b539e0c4ccf133ffbc32478d80e43 --- java/common/rules/impl/java_helper.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index efc7f0e5..e45fac9d 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -168,7 +168,7 @@ def _check_and_get_one_version_attribute(ctx, attr): def _jar_and_target_arg_mapper(jar): # Emit pretty labels for targets in the main repository. label = str(jar.owner) - if label.startswith("@@//"): + if label.startswith("@@//"): # buildifier: disable=canonical-repository label = label.lstrip("@") return jar.path + "," + label From 243a1d4f4b41d5c923868c94b3ebc6d8782580e6 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 31 Jan 2026 02:12:28 -0800 Subject: [PATCH 078/251] Fix a `.jar` file in `java_import.runtime_deps` Wrap it in a separate `java_import` instead. This fixes a java_jars_in_deps_allowlist violation (b/479392897) and doesn't alter the meaning of the test. PiperOrigin-RevId: 863594466 Change-Id: I77bdb2cabdb7394ab95df452df6437a74b202bba --- test/java/common/rules/java_import_tests.bzl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl index 7afbc77b..35b713df 100644 --- a/test/java/common/rules/java_import_tests.bzl +++ b/test/java/common/rules/java_import_tests.bzl @@ -658,11 +658,16 @@ def _test_duplicate_jars_through_filegroup_impl(env, target): def _test_runtime_deps_are_not_on_classpath(name): target_name = name + "/depends_on_runtimedep" + util.helper_target( + java_import, + name = target_name + "/import_runtime", + jars = ["import_runtime.jar"], + ) util.helper_target( java_import, name = target_name + "/import_dep", jars = ["import_compile.jar"], - runtime_deps = ["import_runtime.jar"], + runtime_deps = [target_name + "/import_runtime"], ) util.helper_target( java_library, From 7372e8ccb873074bea26cb9906fcd007b03ad8f9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 2 Feb 2026 07:44:42 -0800 Subject: [PATCH 079/251] chore(docs): add quickstart template link to README (#344) Added a quickstart template link for new projects. Note, this is the same destination reachable from https://bazel.build/start Closes #344 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/344 from alexeagle:patch-1 5fe92bd165e0f6f7f5d6f1c5c58828b3c24965df PiperOrigin-RevId: 864352722 Change-Id: Id64e5414c0ef7b8e339fd2717062f9f856ab5eaa --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e4cfeb0b..52be4f9d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Java Rules for Bazel https://bazel.build. 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 From 1824a5548e56ecd337687ff32baf98e37ddd6b16 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Feb 2026 06:07:52 -0800 Subject: [PATCH 080/251] Add `--sun-misc-unsafe-memory-access=allow` to `JavaBuilder`'s jvm flags Fixes https://github.com/bazelbuild/rules_java/issues/348 PiperOrigin-RevId: 865909019 Change-Id: I1c7fc8857eac63b37aad775b52a4370830513dac --- test/toolchains/BUILD.bazel | 7 +++-- .../default_java_toolchain_tests.bzl | 30 +++++++++++++++++++ toolchains/default_java_toolchain.bzl | 2 ++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 test/toolchains/default_java_toolchain_tests.bzl diff --git a/test/toolchains/BUILD.bazel b/test/toolchains/BUILD.bazel index e25b3d8c..24ae5352 100644 --- a/test/toolchains/BUILD.bazel +++ b/test/toolchains/BUILD.bazel @@ -1,7 +1,8 @@ load(":bootclasspath_tests.bzl", "bootclasspath_tests") +load(":default_java_toolchain_tests.bzl", "default_java_toolchain_tests") package(default_applicable_licenses = ["@rules_java//:license"]) -bootclasspath_tests( - name = "bootclasspath_tests", -) +bootclasspath_tests(name = "bootclasspath_tests") + +default_java_toolchain_tests(name = "default_java_toolchain_tests") diff --git a/test/toolchains/default_java_toolchain_tests.bzl b/test/toolchains/default_java_toolchain_tests.bzl new file mode 100644 index 00000000..bdfa400b --- /dev/null +++ b/test/toolchains/default_java_toolchain_tests.bzl @@ -0,0 +1,30 @@ +"""Tests for the default java toolchain configuration""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") + +def _test_java_builder_jvm_flags(name): + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["A.java"], + ) + analysis_test( + name = name, + impl = _test_java_builder_jvm_flags_impl, + target = name + "/lib", + ) + +def _test_java_builder_jvm_flags_impl(env, target): + env.expect.that_target(target).action_named("Javac").contains_flag_values([ + ("--sun-misc-unsafe-memory-access", "allow"), + ]) + +def default_java_toolchain_tests(name): + test_suite( + name = name, + tests = [ + _test_java_builder_jvm_flags, + ], + ) diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index f4f83f66..df53468a 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -103,6 +103,8 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict( # targeting JDK 7. java_runtime = Label("//toolchains:remotejdk_21"), oneversion = Label("//toolchains:one_version"), + # TODO: remove after https://github.com/protocolbuffers/protobuf/issues/20760 is fixed + javabuilder_jvm_opts = ["--sun-misc-unsafe-memory-access=allow"], ) DEFAULT_TOOLCHAIN_CONFIGURATION = _BASE_TOOLCHAIN_CONFIGURATION From ad1b9c839f1de28ef0413fab334b5bf8c806ed41 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 5 Feb 2026 06:23:56 -0800 Subject: [PATCH 081/251] upgrade jdk25 to 25.0.2 (#349) Closes #349 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/349 from benjaminp:jdk25.0.2 3445d8ab420b7048314b5dcf517ec853a722d32d PiperOrigin-RevId: 865914463 Change-Id: Iab0a058d475653dd9a9c17afc9b46aaee5c4e574 --- java/bazel/repositories_util.bzl | 2 +- java/repositories.bzl | 36 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl index 924bb60f..4cf69561 100644 --- a/java/bazel/repositories_util.bzl +++ b/java/bazel/repositories_util.bzl @@ -88,7 +88,7 @@ _RELEASE_CONFIGS = { }, "25": { "zulu": { - "release": "25.30.17-ca-jdk25.0.1", + "release": "25.32.17-ca-jdk25.0.2", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], diff --git a/java/repositories.bzl b/java/repositories.bzl index 5b1f317e..e3d7d050 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -333,49 +333,49 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk25_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "8c5321f16d9f1d8149f83e4e9ff8ca5d9e94320b92d205e6db42a604de3d1140", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_aarch64.tar.gz"], + sha256 = "f7295abb1decb2f6e0ea9f760a70917f2d47356db4366d615c7ab9b01c3c6866", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz"], version = "25", ), struct( name = "remotejdk25_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "471b3e62bdffaed27e37005d842d8639f10d244ccce1c7cdebf7abce06c8313e", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-linux_x64.tar.gz"], + sha256 = "f1752d0051b6ca233625ddb2c18c9170edbe55c5ee6515bfefd8ea0197ee1c20", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz"], version = "25", ), struct( name = "remotejdk25_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "126061d6046b0c0df0472b361ca7895951d34fef1dd522f222f2c7d8738a39d8", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_aarch64.tar.gz"], + sha256 = "537ac74fa1ca2c4dd8f6063ddede0138ae4a896f128bfe10b428a7dcc4aa929f", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz"], version = "25", ), struct( name = "remotejdk25_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "0154482b317aa63d5158a358e2fab7f0fd6c3c0ba2000b05655c3bcbdd202584", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-macosx_x64.tar.gz"], + sha256 = "fe22346c192920c5b84b23f4aa24e3debb0bb94fc428016f7c2b2c7790c82780", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz"], version = "25", ), struct( name = "remotejdk25_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "4883cf39e8d83679c8a051ace4dd72759d97195a72aaa6727a83bd4bcb97b022", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_aarch64.zip"], + sha256 = "5f44792a12af2100b4db9b5120c27c42af8080ad63bc9eaadc9ca25e5c7dd590", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip"], version = "25", ), struct( name = "remotejdk25_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "72844ba8dddf9259ab9cfda9d515d0c850179705f74278a75973d73f0c5b2d2b", - strip_prefix = "zulu25.30.17-ca-jdk25.0.1-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.30.17-ca-jdk25.0.1-win_x64.zip"], + sha256 = "90bcbbcbe2fb7aec43ce8fd2efa024fcc48f00bbdcd7a76b58f912d6b97e6d56", + strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip"], version = "25", ), ] From d2d725805f1ee6ec8d109a698059ae7a683eb37f Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Thu, 5 Feb 2026 07:34:09 -0800 Subject: [PATCH 082/251] Add remote JDK 25 for riscv64, ppc64le and s390x (#347) A remote JDK 25 is necessary for building Bazel 9. This PR adds remote JDK 25 for riscv64, ppc64le and s390x architectures to fix build failure of bazel 9.0 on these architectures: https://archriscv.felixc.at/.status/log.htm?url=logs/bazel/bazel-9.0.0-1.log Closes #347 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/347 from kxxt:rv25 218f68fb260e3666229289e2e646c02ee39dd3c5 PiperOrigin-RevId: 865939228 Change-Id: I669632c630a02b9fe8af671df9dec8f2c92715c3 --- MODULE.bazel | 3 +++ java/bazel/repositories_util.bzl | 6 ++++++ java/repositories.bzl | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index 23ee0cee..7dbbc2ee 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -100,6 +100,9 @@ JDKS = { "25": [ "linux", "linux_aarch64", + "linux_ppc64le", + "linux_riscv64", + "linux_s390x", "macos", "macos_aarch64", "win", diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl index 4cf69561..40101d37 100644 --- a/java/bazel/repositories_util.bzl +++ b/java/bazel/repositories_util.bzl @@ -95,6 +95,12 @@ _RELEASE_CONFIGS = { "windows": ["arm64", "x86_64"], }, }, + "adoptium": { + "release": "25.0.2+10", + "platforms": { + "linux": ["ppc64le", "riscv64", "s390x"], + }, + }, }, } diff --git a/java/repositories.bzl b/java/repositories.bzl index e3d7d050..5a290b4d 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -378,6 +378,30 @@ _REMOTE_JDK_CONFIGS_LIST = [ urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip"], version = "25", ), + struct( + name = "remotejdk25_linux_ppc64le", + target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc64le"], + sha256 = "b262b735b215173003766da36588d5f717dceada0286db41b439f93fb2ada468", + strip_prefix = "jdk-25.0.2+10", + urls = ["https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_ppc64le_linux_hotspot_25.0.2_10.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_ppc64le_linux_hotspot_25.0.2_10.tar.gz"], + version = "25", + ), + struct( + name = "remotejdk25_linux_riscv64", + target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:riscv64"], + sha256 = "168119e4fba350f4e6b3ca92450a2b90a8502b89a235a04415e9adf9f5d3164e", + strip_prefix = "jdk-25.0.2+10", + urls = ["https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_riscv64_linux_hotspot_25.0.2_10.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_riscv64_linux_hotspot_25.0.2_10.tar.gz"], + version = "25", + ), + struct( + name = "remotejdk25_linux_s390x", + target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"], + sha256 = "15e5cbcadcf3d43623c31b825063cdc2817b9f1ba840b51dc6ef70e5d33c84e3", + strip_prefix = "jdk-25.0.2+10", + urls = ["https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_s390x_linux_hotspot_25.0.2_10.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.2+10/OpenJDK25U-jdk_s390x_linux_hotspot_25.0.2_10.tar.gz"], + version = "25", + ), ] def _make_version_to_remote_jdks(): From bef4f9893536fd1b41589a44a85863dc6b81e1b0 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Feb 2026 08:48:39 -0800 Subject: [PATCH 083/251] Add testing for Bazel 9 to `@rules_java` CI Also switch from using fixed versions with latest release for each major version. PiperOrigin-RevId: 865968441 Change-Id: I9809f82cd9e6ece901b1cd7a4e5754b17196581d --- .bazelci/presubmit.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 4fe6a435..30c63935 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -34,8 +34,8 @@ buildifier: latest matrix: all_platforms: ["rockylinux8_arm64", "ubuntu2004", "macos", "macos_arm64", "windows"] - bazel: ["7.7.1", "8.4.2", "last_green"] - modern_bazel: ["last_green", "rolling"] # Fully supported Bazel versions + bazel: ["7.x", "8.x", "9.x", "last_green"] + modern_bazel: ["9.x", "last_green", "rolling"] # Fully supported Bazel versions tasks: # Bazel 9+ @@ -47,8 +47,8 @@ tasks: test_targets: *test_targets # Bazel 8.x build_and_test_bazel8: - name: "Bazel 8.4.2" - bazel: "8.4.2" + name: "Bazel 8.x" + bazel: "8.x" platform: ${{ all_platforms }} build_targets: *build_targets test_targets: *test_targets @@ -56,8 +56,8 @@ tasks: - "--test_tag_filters=-min_bazel_9" # Bazel 7.x build_and_test_bazel7: - name: "Bazel 7.7.1" - bazel: "7.7.1" + name: "Bazel 7.x" + bazel: "7.x" platform: ${{ all_platforms }} build_targets: *build_targets test_targets: *test_targets From 4566a5d621cd7943eda31aba6f63049cb43aef66 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 7 Feb 2026 01:18:24 -0800 Subject: [PATCH 084/251] Fix `java_single_jar` compatibility with Bazel 7 Rule extension APIs weren't enabled by default in Bazel 7, so the rule was broken after https://github.com/bazelbuild/rules_java/commit/37b099cfd27de53495aea44763a16cd23ff929df Also add a dummy target under `test/repo` to build as a regression test. Fixes https://github.com/bazelbuild/rules_java/issues/350 PiperOrigin-RevId: 866808173 Change-Id: I594f0194be02f935154585e68d091172140301e1 --- java/BUILD | 4 +- java/bazel/rules/bazel_java_single_jar.bzl | 21 +++ java/common/rules/BUILD | 8 + java/common/rules/java_single_jar.bzl | 167 +++++++++++++++++++++ java/java_single_jar.bzl | 159 +------------------- test/repo/BUILD.bazel | 10 ++ 6 files changed, 212 insertions(+), 157 deletions(-) create mode 100644 java/bazel/rules/bazel_java_single_jar.bzl create mode 100644 java/common/rules/java_single_jar.bzl diff --git a/java/BUILD b/java/BUILD index 452c7654..7888daba 100644 --- a/java/BUILD +++ b/java/BUILD @@ -65,7 +65,9 @@ bzl_library( name = "java_single_jar", srcs = ["java_single_jar.bzl"], visibility = ["//visibility:public"], - deps = ["//java/common"], + deps = [ + "//java/bazel/rules", # copybara-use-repo-external-label + ], ) bzl_library( diff --git a/java/bazel/rules/bazel_java_single_jar.bzl b/java/bazel/rules/bazel_java_single_jar.bzl new file mode 100644 index 00000000..922fb638 --- /dev/null +++ b/java/bazel/rules/bazel_java_single_jar.bzl @@ -0,0 +1,21 @@ +# Copyright 2026 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Bazel java_single_jar rule""" + +load("//java/common/rules:java_single_jar.bzl", _bazel_java_single_jar = "bazel_java_single_jar") + +def java_single_jar(*, name, **kwargs): + if "output" not in kwargs: + kwargs["output"] = name + ".jar" + _bazel_java_single_jar(name = name, **kwargs) diff --git a/java/common/rules/BUILD b/java/common/rules/BUILD index 5bb5c2fb..f6fde9d4 100644 --- a/java/common/rules/BUILD +++ b/java/common/rules/BUILD @@ -31,6 +31,13 @@ bzl_library( visibility = ["//java:__subpackages__"], ) +bzl_library( + name = "java_single_jar_bzl", + srcs = ["java_single_jar.bzl"], + visibility = ["//java:__subpackages__"], + deps = ["//java/common"], +) + bzl_library( name = "core_rules", srcs = [ @@ -81,6 +88,7 @@ filegroup( srcs = [ "BUILD", ":core_rules", + ":java_single_jar_bzl", ":toolchain_rules", "//java/common/rules/impl:for_bazel_tests", "@rules_cc//cc/private/rules_impl:srcs", diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl new file mode 100644 index 00000000..95b7ca2e --- /dev/null +++ b/java/common/rules/java_single_jar.bzl @@ -0,0 +1,167 @@ +# Copyright 2026 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Definition of the java_single_jar rule.""" + +load("//java/common:java_common.bzl", "java_common") +load("//java/common:java_info.bzl", "JavaInfo") + +# copybara: default visibility + +def _single_jar_inputs(deps, deploy_env): + transitive_inputs = [] + for dep in deps: + if JavaInfo in dep: + info = dep[JavaInfo] + transitive_inputs.append(info.transitive_runtime_jars) + if hasattr(info, "compilation_info"): + compilation_info = info.compilation_info + if hasattr(compilation_info, "runtime_classpath"): + transitive_inputs.append(compilation_info.runtime_classpath) + else: + files = [] + for f in dep[DefaultInfo].files.to_list(): + if not f.extension == "jar": + fail("unexpected file type in java_single_jar.deps: %s" % f.path) + files.append(f) + transitive_inputs.append(depset(files)) + inputs = depset(transitive = transitive_inputs) + + if hasattr(java_common, "JavaRuntimeClasspathInfo"): + deploy_env_jars = depset(transitive = [ + dep[java_common.JavaRuntimeClasspathInfo].runtime_classpath + for dep in deploy_env + ]) + excluded_jars = {jar: None for jar in deploy_env_jars.to_list()} + if excluded_jars: + inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars]) + return inputs + +def _bazel_java_single_jar_impl(ctx): + inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) + + args = ctx.actions.args() + args.add_all("--sources", inputs) + args.use_param_file("@%s") + args.set_param_file_format("multiline") + args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines) + args.add("--output", ctx.outputs.output) + args.add("--normalize") + + # Deal with limitation of singlejar flags: tool's default behavior is + # "no", but you get that behavior only by absence of compression flags. + if ctx.attr.compress == "preserve": + args.add("--dont_change_compression") + elif ctx.attr.compress == "yes": + args.add("--compression") + elif ctx.attr.compress == "no": + pass + else: + fail("\"compress\" attribute (%s) must be: yes, no, preserve." % ctx.attr.compress) + + if ctx.attr.exclude_build_data: + args.add("--exclude_build_data") + if ctx.attr.multi_release: + args.add("--multi_release") + + if ctx.attr.exclude_pattern: + args.add("--exclude_pattern", ctx.attr.exclude_pattern) + + ctx.actions.run( + inputs = inputs, + outputs = [ctx.outputs.output], + arguments = [args], + progress_message = "Merging into %s" % ctx.outputs.output.short_path, + mnemonic = "JavaSingleJar", + executable = ctx.executable._singlejar, + use_default_shell_env = True, + ) + + files = depset([ctx.outputs.output]) + providers = [DefaultInfo( + files = files, + runfiles = ctx.runfiles(transitive_files = files), + )] + if hasattr(java_common, "JavaRuntimeClasspathInfo"): + providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs)) + return providers + +bazel_java_single_jar = rule( + attrs = { + "deps": attr.label_list( + allow_files = True, + doc = """ + The Java targets (including java_import and java_library) to collect + transitive dependencies from. Runtime dependencies are collected via + deps, exports, and runtime_deps. Resources are also collected. + Native cc_library or java_wrap_cc dependencies are not.""", + ), + "deploy_manifest_lines": attr.string_list(doc = """ + A list of lines to add to the META-INF/manifest.mf file."""), + "deploy_env": attr.label_list( + providers = [java_common.JavaRuntimeClasspathInfo] if hasattr(java_common, "JavaRuntimeClasspathInfo") else [], + allow_files = False, + doc = """ + A list of `java_binary` or `java_single_jar` targets which represent + the deployment environment for this binary. + + Set this attribute when building a plugin which will be loaded by another + `java_binary`. + + `deploy_env` dependencies are excluded from the jar built by this rule.""", + ), + "compress": attr.string(default = "preserve", doc = """ + Whether to always deflate ("yes"), always store ("no"), or pass + through unmodified ("preserve"). The default is "preserve", and is the + most efficient option -- no extra work is done to inflate or deflate."""), + "exclude_build_data": attr.bool(default = True, doc = """ + Whether to omit the build-data.properties file generated + by default."""), + "multi_release": attr.bool(default = True, doc = """Whether to enable Multi-Release output jars."""), + "exclude_pattern": attr.string(default = "", doc = """ + A regex pattern of files to exclude from the jar. + """), + "_singlejar": attr.label( + default = Label("//toolchains:singlejar"), + cfg = "exec", + allow_single_file = True, + executable = True, + ), + "output": attr.output(), + }, + implementation = _bazel_java_single_jar_impl, + doc = """ +Collects Java dependencies and jar files into a single jar + +`java_single_jar` collects Java dependencies and jar files into a single jar. +This is similar to java_binary with everything related to executables disabled, +and provides an alternative to the java_binary "deploy jar hack". + +## Example + +```skylark +load("//tools/build_defs/java_single_jar:java_single_jar.bzl", "java_single_jar") + +java_single_jar( + name = "my_single_jar", + deps = [ + "//java/com/google/foo", + "//java/com/google/bar", + ], +) +``` + +Outputs: + {name}.jar: A single jar containing all of the inputs. +""", +) diff --git a/java/java_single_jar.bzl b/java/java_single_jar.bzl index bfdd21c0..84771614 100644 --- a/java/java_single_jar.bzl +++ b/java/java_single_jar.bzl @@ -1,158 +1,5 @@ -""" Definition of _java_single_jar. """ +"""The java_single_jar rule""" -load("//java/common:java_common.bzl", "java_common") -load("//java/common:java_info.bzl", "JavaInfo") +load("//java/bazel/rules:bazel_java_single_jar.bzl", _java_single_jar = "java_single_jar") -def _single_jar_inputs(deps, deploy_env): - transitive_inputs = [] - for dep in deps: - if JavaInfo in dep: - info = dep[JavaInfo] - transitive_inputs.append(info.transitive_runtime_jars) - if hasattr(info, "compilation_info"): - compilation_info = info.compilation_info - if hasattr(compilation_info, "runtime_classpath"): - transitive_inputs.append(compilation_info.runtime_classpath) - else: - files = [] - for f in dep[DefaultInfo].files.to_list(): - if not f.extension == "jar": - fail("unexpected file type in java_single_jar.deps: %s" % f.path) - files.append(f) - transitive_inputs.append(depset(files)) - inputs = depset(transitive = transitive_inputs) - - if hasattr(java_common, "JavaRuntimeClasspathInfo"): - deploy_env_jars = depset(transitive = [ - dep[java_common.JavaRuntimeClasspathInfo].runtime_classpath - for dep in deploy_env - ]) - excluded_jars = {jar: None for jar in deploy_env_jars.to_list()} - if excluded_jars: - inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars]) - return inputs - -def _java_single_jar(ctx): - inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) - - args = ctx.actions.args() - args.add_all("--sources", inputs) - args.use_param_file("@%s") - args.set_param_file_format("multiline") - args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines) - args.add("--output", ctx.outputs.output) - args.add("--normalize") - - # Deal with limitation of singlejar flags: tool's default behavior is - # "no", but you get that behavior only by absence of compression flags. - if ctx.attr.compress == "preserve": - args.add("--dont_change_compression") - elif ctx.attr.compress == "yes": - args.add("--compression") - elif ctx.attr.compress == "no": - pass - else: - fail("\"compress\" attribute (%s) must be: yes, no, preserve." % ctx.attr.compress) - - if ctx.attr.exclude_build_data: - args.add("--exclude_build_data") - if ctx.attr.multi_release: - args.add("--multi_release") - - if ctx.attr.exclude_pattern: - args.add("--exclude_pattern", ctx.attr.exclude_pattern) - - ctx.actions.run( - inputs = inputs, - outputs = [ctx.outputs.output], - arguments = [args], - progress_message = "Merging into %s" % ctx.outputs.output.short_path, - mnemonic = "JavaSingleJar", - executable = ctx.executable._singlejar, - use_default_shell_env = True, - ) - - files = depset([ctx.outputs.output]) - providers = [DefaultInfo( - files = files, - runfiles = ctx.runfiles(transitive_files = files), - )] - if hasattr(java_common, "JavaRuntimeClasspathInfo"): - providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs)) - return providers - -def _init(name, **kwargs): - if "output" not in kwargs: - kwargs["output"] = name + ".jar" - return kwargs - -java_single_jar = rule( - attrs = { - "deps": attr.label_list( - allow_files = True, - doc = """ - The Java targets (including java_import and java_library) to collect - transitive dependencies from. Runtime dependencies are collected via - deps, exports, and runtime_deps. Resources are also collected. - Native cc_library or java_wrap_cc dependencies are not.""", - ), - "deploy_manifest_lines": attr.string_list(doc = """ - A list of lines to add to the META-INF/manifest.mf file."""), - "deploy_env": attr.label_list( - providers = [java_common.JavaRuntimeClasspathInfo] if hasattr(java_common, "JavaRuntimeClasspathInfo") else [], - allow_files = False, - doc = """ - A list of `java_binary` or `java_single_jar` targets which represent - the deployment environment for this binary. - - Set this attribute when building a plugin which will be loaded by another - `java_binary`. - - `deploy_env` dependencies are excluded from the jar built by this rule.""", - ), - "compress": attr.string(default = "preserve", doc = """ - Whether to always deflate ("yes"), always store ("no"), or pass - through unmodified ("preserve"). The default is "preserve", and is the - most efficient option -- no extra work is done to inflate or deflate."""), - "exclude_build_data": attr.bool(default = True, doc = """ - Whether to omit the build-data.properties file generated - by default."""), - "multi_release": attr.bool(default = True, doc = """Whether to enable Multi-Release output jars."""), - "exclude_pattern": attr.string(default = "", doc = """ - A regex pattern of files to exclude from the jar. - """), - "_singlejar": attr.label( - default = Label("//toolchains:singlejar"), - cfg = "exec", - allow_single_file = True, - executable = True, - ), - "output": attr.output(), - }, - initializer = _init, - implementation = _java_single_jar, - doc = """ -Collects Java dependencies and jar files into a single jar - -`java_single_jar` collects Java dependencies and jar files into a single jar. -This is similar to java_binary with everything related to executables disabled, -and provides an alternative to the java_binary "deploy jar hack". - -## Example - -```skylark -load("//tools/build_defs/java_single_jar:java_single_jar.bzl", "java_single_jar") - -java_single_jar( - name = "my_single_jar", - deps = [ - "//java/com/google/foo", - "//java/com/google/bar", - ], -) -``` - -Outputs: - {name}.jar: A single jar containing all of the inputs. -""", -) +java_single_jar = _java_single_jar diff --git a/test/repo/BUILD.bazel b/test/repo/BUILD.bazel index b0fb6122..a251c7b7 100644 --- a/test/repo/BUILD.bazel +++ b/test/repo/BUILD.bazel @@ -1,4 +1,5 @@ load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test") # copybara-use-repo-external-label +load("@rules_java//java:java_single_jar.bzl", "java_single_jar") # copybara-use-repo-external-label load("@rules_java//toolchains:default_java_toolchain.bzl", "NONPREBUILT_TOOLCHAIN_CONFIGURATION", "default_java_toolchain") # copybara-use-repo-external-label load("@rules_shell//shell:sh_test.bzl", "sh_test") @@ -27,6 +28,15 @@ java_test( ], ) +java_single_jar( + name = "uber", + testonly = True, + deps = [ + ":MyTest", + ":bin", + ], +) + genrule( name = "MakeVarGenruleTest", outs = ["MakeVarGenruleTestSuccess"], From 7eb8b69c07712d2502b2a78b7fe9f30e3054a422 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 Feb 2026 03:04:16 -0800 Subject: [PATCH 085/251] Release `@rules_java` `v9.4.0` PiperOrigin-RevId: 867508885 Change-Id: Id3610cbe51704aa8c23ea8ad6e1feca3f2fdd231 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 7dbbc2ee..4dcb582e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.3.0", + version = "9.4.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From f70e12608c04cdf3467b429478439b247095c129 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 Feb 2026 05:13:25 -0800 Subject: [PATCH 086/251] Run `@rules_java` extra tests only with the latest Bazel release The tests only exercise internals (such as the release process or configs) and should be independent of the Bazel version. Running them (esp the remote jdk configs tests) with all Bazel versions is wasteful. PiperOrigin-RevId: 867550547 Change-Id: Ic6803c9b00b83381706005aa3e0a6528199fdabb --- .bazelci/presubmit.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 30c63935..411f490c 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -89,10 +89,9 @@ tasks: build_flags: *flags_workspace_integration test_targets: *test_target_integration test_flags: *flags_workspace_integration -# Linux-only tests - linux_only_tests: - name: "Extra tests w/ Bazel {bazel}" - bazel: ${{ bazel }} + # internal tests for configs and release process + internal_tests: + name: "Internal tests" platform: "ubuntu2004" shell_commands: - "git init" From 7e5a90c268d33254cf2b2c0ef651fba754b75efe Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 04:03:07 -0800 Subject: [PATCH 087/251] Fix `bzl_library` graph for `java_single_jar` Also add a `starlark_doc_extract` target as a regression test PiperOrigin-RevId: 868067494 Change-Id: I1d373d9f40a49bb3affea1eb1ec4ce263b610662 --- java/BUILD | 2 +- java/bazel/rules/BUILD.bazel | 16 +++++++++++++++- test/BUILD.bazel | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/java/BUILD b/java/BUILD index 7888daba..b613191c 100644 --- a/java/BUILD +++ b/java/BUILD @@ -66,7 +66,7 @@ bzl_library( srcs = ["java_single_jar.bzl"], visibility = ["//visibility:public"], deps = [ - "//java/bazel/rules", # copybara-use-repo-external-label + "//java/bazel/rules:java_single_jar_bzl", # copybara-use-repo-external-label ], ) diff --git a/java/bazel/rules/BUILD.bazel b/java/bazel/rules/BUILD.bazel index e0d79586..108a3f9c 100644 --- a/java/bazel/rules/BUILD.bazel +++ b/java/bazel/rules/BUILD.bazel @@ -23,7 +23,10 @@ filegroup( bzl_library( name = "rules", - srcs = glob(["*.bzl"]), + srcs = glob( + ["*.bzl"], + exclude = ["bazel_java_single_jar.bzl"], + ), visibility = ["//visibility:public"], # for Bazel docgen deps = [ "//java/common:semantics_bzl", @@ -36,6 +39,17 @@ bzl_library( ], ) +bzl_library( + name = "java_single_jar_bzl", + srcs = ["bazel_java_single_jar.bzl"], + visibility = [ + "//java:__pkg__", + ], + deps = [ + "//java/common/rules:java_single_jar_bzl", + ], +) + filegroup( name = "for_bazel_tests", testonly = 1, diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 964c77cb..951280d6 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -81,3 +81,9 @@ starlark_doc_extract( src = "@compatibility_proxy//:proxy.bzl", deps = ["@compatibility_proxy//:proxy_bzl"], ) + +starlark_doc_extract( + name = "java_single_jar_bzl_graph", + src = "//java:java_single_jar.bzl", + deps = ["//java:java_single_jar"], +) From aade08e392f741cf73b2f6edbde9831b3b0f066b Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 04:11:03 -0800 Subject: [PATCH 088/251] Release `@rules_java` `v9.4.1` PiperOrigin-RevId: 868071534 Change-Id: Idf9d65b24bf1ea7c2a018c4e2c7fe3582c2abea4 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 4dcb582e..a7621b1c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.4.0", + version = "9.4.1", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From aa4075b7ba2057b65f787324c175c0b433dacc43 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 05:46:09 -0800 Subject: [PATCH 089/251] Automated rollback of commit 1824a5548e56ecd337687ff32baf98e37ddd6b16. *** Reason for rollback *** Breaks Bazel tests *** Original change description *** Add `--sun-misc-unsafe-memory-access=allow` to `JavaBuilder`'s jvm flags Fixes https://github.com/bazelbuild/rules_java/issues/348 PiperOrigin-RevId: 868102114 Change-Id: If58378b00718c8ca3a04d2559801c8540c006ad6 --- test/toolchains/BUILD.bazel | 7 ++--- .../default_java_toolchain_tests.bzl | 30 ------------------- toolchains/default_java_toolchain.bzl | 2 -- 3 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 test/toolchains/default_java_toolchain_tests.bzl diff --git a/test/toolchains/BUILD.bazel b/test/toolchains/BUILD.bazel index 24ae5352..e25b3d8c 100644 --- a/test/toolchains/BUILD.bazel +++ b/test/toolchains/BUILD.bazel @@ -1,8 +1,7 @@ load(":bootclasspath_tests.bzl", "bootclasspath_tests") -load(":default_java_toolchain_tests.bzl", "default_java_toolchain_tests") package(default_applicable_licenses = ["@rules_java//:license"]) -bootclasspath_tests(name = "bootclasspath_tests") - -default_java_toolchain_tests(name = "default_java_toolchain_tests") +bootclasspath_tests( + name = "bootclasspath_tests", +) diff --git a/test/toolchains/default_java_toolchain_tests.bzl b/test/toolchains/default_java_toolchain_tests.bzl deleted file mode 100644 index bdfa400b..00000000 --- a/test/toolchains/default_java_toolchain_tests.bzl +++ /dev/null @@ -1,30 +0,0 @@ -"""Tests for the default java toolchain configuration""" - -load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") -load("@rules_testing//lib:util.bzl", "util") -load("//java:java_library.bzl", "java_library") - -def _test_java_builder_jvm_flags(name): - util.helper_target( - java_library, - name = name + "/lib", - srcs = ["A.java"], - ) - analysis_test( - name = name, - impl = _test_java_builder_jvm_flags_impl, - target = name + "/lib", - ) - -def _test_java_builder_jvm_flags_impl(env, target): - env.expect.that_target(target).action_named("Javac").contains_flag_values([ - ("--sun-misc-unsafe-memory-access", "allow"), - ]) - -def default_java_toolchain_tests(name): - test_suite( - name = name, - tests = [ - _test_java_builder_jvm_flags, - ], - ) diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index df53468a..f4f83f66 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -103,8 +103,6 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict( # targeting JDK 7. java_runtime = Label("//toolchains:remotejdk_21"), oneversion = Label("//toolchains:one_version"), - # TODO: remove after https://github.com/protocolbuffers/protobuf/issues/20760 is fixed - javabuilder_jvm_opts = ["--sun-misc-unsafe-memory-access=allow"], ) DEFAULT_TOOLCHAIN_CONFIGURATION = _BASE_TOOLCHAIN_CONFIGURATION From 6c9bc7791fedcb87208a3f2bb33818c29fa2553a Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 06:50:23 -0800 Subject: [PATCH 090/251] Fix javacopts expansion We need to perform location expansion first, otherwise `$(location ...)` is treated as a make variable. Actually fixes https://github.com/bazelbuild/rules_java/issues/345 PiperOrigin-RevId: 868123902 Change-Id: I74d38c34f55990d4afc76498567a7740f58aa39e --- java/common/rules/impl/compile_action.bzl | 2 +- test/java/bazel/rules/java_binary_tests.bzl | 21 +++++++++++++++++++++ test/java/testutil/java_info_subject.bzl | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/java/common/rules/impl/compile_action.bzl b/java/common/rules/impl/compile_action.bzl index 098c55bb..f553a837 100644 --- a/java/common/rules/impl/compile_action.bzl +++ b/java/common/rules/impl/compile_action.bzl @@ -136,9 +136,9 @@ def compile_action( or resources present, whereas runfiles in this case are empty. """ expanded_javacopts = javacopts + expanded_javacopts = [ctx.expand_location(opt) for opt in expanded_javacopts] if semantics.expand_javacopts_make_variables: expanded_javacopts = [ctx.expand_make_variables("javacopts", opt, {}) for opt in expanded_javacopts] - expanded_javacopts = [ctx.expand_location(opt) for opt in expanded_javacopts] java_info = _compile_private_for_builtins( ctx, output = output_class_jar, diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 2d015b67..737acea9 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -77,11 +77,32 @@ def _test_java_binary_javacopts_make_variable_expansion_impl(env, target): assert_java_info.compilation_info().javac_options().not_contains("$(MY_CUSTOM_OPT)") assert_java_info.compilation_info().javac_options().contains("MY_OPT_VALUE") +def _test_java_binary_javacopts_location_expansion(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["A.java"], + javacopts = ["-XepOpt:foo=$(location :A.java)"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_javacopts_location_expansion_impl, + target = name + "/bin", + ) + +def _test_java_binary_javacopts_location_expansion_impl(env, target): + assert_java_info = java_info_subject.from_target(env, target) + assert_java_info.compilation_info().javac_options().contains( + "-XepOpt:foo={package}/A.java", + ) + def java_binary_tests(name): test_suite( name = name, tests = [ _test_java_binary_cross_compilation_to_unix, _test_java_binary_javacopts_make_variable_expansion, + _test_java_binary_javacopts_location_expansion, ], ) diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index e9242436..e0ec8059 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -58,7 +58,7 @@ def _new_java_compilation_info_subject(java_info, meta): compilation_classpath = lambda: subjects.depset_file(self.actual.compilation_classpath, self.meta.derive("compilation_classpath")), runtime_classpath = lambda: subjects.depset_file(self.actual.runtime_classpath, self.meta.derive("runtime_classpath")), runtime_classpath_list = lambda: subjects.collection(self.actual.runtime_classpath.to_list(), self.meta.derive("runtime_classpath.to_list()"), format = True), - javac_options = lambda: subjects.collection(helper.tokenize_javacopts(opts = self.actual.javac_options), self.meta.derive("javac_options")), + javac_options = lambda: subjects.collection(helper.tokenize_javacopts(opts = self.actual.javac_options), self.meta.derive("javac_options"), format = True), ) return public From 4beb813a365a97701d4dd4e56efced1b47eac3e3 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 06:59:47 -0800 Subject: [PATCH 091/251] Release `rules_java` `v9.4.2` PiperOrigin-RevId: 868127673 Change-Id: Id112970e9fb5a5a882d77a96ad179592eb901df3 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index a7621b1c..e4e88698 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.4.1", + version = "9.4.2", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 06662838f1ecc7a9653b16e40f9541e729fe06d7 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 08:31:37 -0800 Subject: [PATCH 092/251] Update `java_tools` to `v19.0` For changes from https://github.com/bazelbuild/bazel/pull/28340 PiperOrigin-RevId: 868161177 Change-Id: I96fe102432d7c45ccf463eb32b07a70534785986 --- MODULE.bazel | 1 + java/repositories.bzl | 39 ++++++++++++++++++++------------------- java/rules_java_deps.bzl | 12 ++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index e4e88698..fc847b0b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -22,6 +22,7 @@ bazel_dep(name = "zlib", version = "1.3.1.bcr.5") # Required by @remote_java_tools, which is loaded via module extension. bazel_dep(name = "rules_license", version = "0.0.3") bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl") +bazel_dep(name = "re2", version = "2025-11-05.bcr.1") single_version_override( module_name = "protobuf", diff --git a/java/repositories.bzl b/java/repositories.bzl index 5a290b4d..df95f86d 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,38 +22,39 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v18.1", + "version": "v19.0", + "source_revision": "61972bfd7fb6f587fc4576b5114e20758b501806", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_linux-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_linux-v18.1.zip", - "sha": "e22cbb2600249576c6a0a02af3f78e26537a89b6be11ef3826c01f9019faaa61", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux-v19.0.zip", + "sha": "7d5b0c01f99ea5596b7901a7e5f9173f3ae3c4f0b480378e87567eaf97d75d25", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_linux_aarch64-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_linux_aarch64-v18.1.zip", - "sha": "4f75420bafb8c6554105c90ed05db3d7ff5942dbc1633459c20d2dcc06eff6ac", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux_aarch64-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux_aarch64-v19.0.zip", + "sha": "34b14fdfe8d6e32ed7f80e7c4d34ce79f4006e0d4b621552f507e51b9d6a3d7d", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_windows-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_windows-v18.1.zip", - "sha": "fe6dccef1b290b9e2a539cecfd57d924f719480ac04e55d03fdca5533272cd04", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_windows-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_windows-v19.0.zip", + "sha": "86c5a58ccefdb9e704fddd325f5fbc7867b2cdd128fb8b9abfdf607a75d2ae71", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_darwin_x86_64-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_darwin_x86_64-v18.1.zip", - "sha": "68f6b540a28ff1d98acd9313900c50560d52022ee2399627b9c92b1bb2c5d466", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_x86_64-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_x86_64-v19.0.zip", + "sha": "78ff8ec7038ab5f9cd261cdf9ff75ea0eb2af7579f9aeef9d658459ee37fabac", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools_darwin_arm64-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools_darwin_arm64-v18.1.zip", - "sha": "07026303be4662462733d00eaf8e956cd9589493e104934862f0b53e76758d88", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_arm64-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_arm64-v19.0.zip", + "sha": "86f15280dd0ce121a22f061e2e301ecf746597caa4938cf56852b3d311b830d8", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v18.1/java_tools-v18.1.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v18.1/java_tools-v18.1.zip", - "sha": "27cab59ba5ff8ee7cf3071971fe2587a295daefe82531f27b4f061111276163d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools-v19.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools-v19.0.zip", + "sha": "d21d4aad1a18062512bcf4e8f7a09a4f5a042c760daa779e0ddda6e41b170507", }, }, } diff --git a/java/rules_java_deps.bzl b/java/rules_java_deps.bzl index 1eb28492..b2086dc1 100644 --- a/java/rules_java_deps.bzl +++ b/java/rules_java_deps.bzl @@ -209,6 +209,17 @@ def rules_license_repo(): ], ) +def re2_repo(): + maybe( + http_archive, + name = "re2", + sha256 = "5bb6875ae1cd1e9fedde98018c346db7260655f86fdb8837e3075103acd3649b", + strip_prefix = "re2-2023-09-01", + urls = [ + "https://github.com/google/re2/releases/download/2023-09-01/re2-2023-09-01.tar.gz", + ], + ) + def rules_java_dependencies(): """An utility method to load non-toolchain dependencies of rules_java. @@ -222,3 +233,4 @@ def rules_java_dependencies(): zlib_repo() absl_repo() rules_license_repo() + re2_repo() From 14642c5529672185b07fe0a1104c62dee2a7a292 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Feb 2026 08:45:43 -0800 Subject: [PATCH 093/251] Release `rules_java` `v9.5.0` PiperOrigin-RevId: 868166803 Change-Id: I4438f95a6906264a19b5b6063376f77141e35d68 --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index fc847b0b..70e975f3 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.4.2", + version = "9.5.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 2039d00740729ecc91aea49da2853315263397cb Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 11 Feb 2026 02:17:26 -0800 Subject: [PATCH 094/251] Remove handling for empty java_imports jars PiperOrigin-RevId: 868566387 Change-Id: I30797623e04eda8d7849d059655b9b036aac0d42 --- .../rules/impl/bazel_java_import_impl.bzl | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index 7ca9cf7d..2a107a1e 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl @@ -74,26 +74,6 @@ def _check_empty_jars_error(ctx, jars): if len(jars) == 0: fail("empty java_import.jars is not supported " + ctx.label.package) -def _create_java_info_with_dummy_output_file(ctx, srcjar, all_deps, exports, runtime_deps_list, neverlink, cc_info_list, add_exports, add_opens): - dummy_jar = ctx.actions.declare_file(ctx.label.name + "_dummy.jar") - dummy_src_jar = srcjar - if dummy_src_jar == None: - dummy_src_jar = ctx.actions.declare_file(ctx.label.name + "_src_dummy.java") - ctx.actions.write(dummy_src_jar, "") - return java_common.compile( - ctx, - output = dummy_jar, - java_toolchain = semantics.find_java_toolchain(ctx), - source_files = [dummy_src_jar], - deps = all_deps, - runtime_deps = runtime_deps_list, - neverlink = neverlink, - exports = [export[JavaInfo] for export in exports if JavaInfo in export], # Watchout, maybe you need to add them there manually. - native_libraries = cc_info_list, - add_exports = add_exports, - add_opens = add_opens, - ) - def bazel_java_import_rule( ctx, jars = [], @@ -135,7 +115,7 @@ def bazel_java_import_rule( jdeps_artifact = None merged_java_info = java_common.merge(all_deps) not_in_allowlist = hasattr(ctx.attr, "_allowlist_java_import_deps_checking") and not ctx.attr._allowlist_java_import_deps_checking[PackageSpecificationInfo].contains(ctx.label) - if len(collected_jars) > 0 and not_in_allowlist and "incomplete-deps" not in ctx.attr.tags: + if not_in_allowlist and "incomplete-deps" not in ctx.attr.tags: jdeps_artifact = import_deps_check( ctx, collected_jars, @@ -147,26 +127,21 @@ def bazel_java_import_rule( compilation_to_runtime_jar_map = _process_with_ijars_if_needed(collected_jars, ctx) runtime_deps_list = [runtime_dep[JavaInfo] for runtime_dep in runtime_deps if JavaInfo in runtime_dep] cc_info_list = [dep[CcInfo] for dep in deps if CcInfo in dep] - java_info = None - if len(collected_jars) > 0: - java_infos = [] - for jar in collected_jars: - java_infos.append(JavaInfo( - output_jar = jar, - compile_jar = compilation_to_runtime_jar_map[jar], - deps = all_deps, - runtime_deps = runtime_deps_list, - neverlink = neverlink, - source_jar = srcjar, - exports = [export[JavaInfo] for export in exports if JavaInfo in export], # Watchout, maybe you need to add them there manually. - native_libraries = cc_info_list, - add_exports = add_exports, - add_opens = add_opens, - )) - java_info = java_common.merge(java_infos) - else: - # TODO(kotlaja): Remove next line once all java_import targets with empty jars attribute are cleaned from depot (b/246559727). - java_info = _create_java_info_with_dummy_output_file(ctx, srcjar, all_deps, exports, runtime_deps_list, neverlink, cc_info_list, add_exports, add_opens) + java_infos = [] + for jar in collected_jars: + java_infos.append(JavaInfo( + output_jar = jar, + compile_jar = compilation_to_runtime_jar_map[jar], + deps = all_deps, + runtime_deps = runtime_deps_list, + neverlink = neverlink, + source_jar = srcjar, + exports = [export[JavaInfo] for export in exports if JavaInfo in export], # Watchout, maybe you need to add them there manually. + native_libraries = cc_info_list, + add_exports = add_exports, + add_opens = add_opens, + )) + java_info = java_common.merge(java_infos) target = {"JavaInfo": java_info} From 10e179c4175c8aad26ff0b8378644fa041bb17c4 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 11 Feb 2026 02:37:42 -0800 Subject: [PATCH 095/251] Adds a test for compilation_outputs output group to java_binary_tests.bzl PiperOrigin-RevId: 868573491 Change-Id: I2188753f333db240945ff2b7e250adf8f07fe2a9 --- test/java/common/rules/java_binary_tests.bzl | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 97a85713..9ddadbd9 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -167,6 +167,33 @@ def _test_java_binary_propagates_direct_native_libraries_impl(env, target): matching.str_matches("-Djava.library.path=${JAVA_RUNFILES}/*/test_java_binary_propagates_direct_native_libraries"), ) +def _test_java_compile_only(name): + util.helper_target( + java_library, + name = name + "/hello_library", + srcs = ["HelloLibrary.java"], + ) + util.helper_target( + java_binary, + name = name + "/main", + srcs = ["Main.java"], + main_class = "main.Main", + deps = [name + "/hello_library"], + ) + + analysis_test( + name = name, + impl = _test_java_compile_only_impl, + target = name + "/main", + ) + +def _test_java_compile_only_impl(env, target): + # Assert that the compilation output is exactly main jar, and does not contain a variant of + # hello_library.jar. + env.expect.that_target(target).output_group( + "compilation_outputs", + ).contains_exactly(["{package}/{name}.jar"]) + def java_binary_tests(name): test_suite( name = name, @@ -175,5 +202,6 @@ def java_binary_tests(name): _test_stamp_conversion_does_not_override_int, _test_java_binary_attributes, _test_java_binary_propagates_direct_native_libraries, + _test_java_compile_only, ], ) From 42139be27a212989a3b67626e27904ca55602788 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 11 Feb 2026 08:50:44 -0800 Subject: [PATCH 096/251] Remove `add_exports` and `add_opens` parameters from `java_common.compile` PiperOrigin-RevId: 868699430 Change-Id: I10351f8187e4ff0966123e00a99cb6599f8a45ce --- java/private/java_common.bzl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 8a465c26..3c11c0e8 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl @@ -65,9 +65,7 @@ def _compile( sourcepath = [], resources = [], neverlink = False, - enable_annotation_processing = True, - add_exports = [], - add_opens = []): + enable_annotation_processing = True): return _compile_internal( ctx, output = output, @@ -90,8 +88,6 @@ def _compile( resources = resources, neverlink = neverlink, enable_annotation_processing = enable_annotation_processing, - add_exports = add_exports, - add_opens = add_opens, ) def _run_ijar(actions, jar, java_toolchain, target_label = None): From 1cd7671a230ab703d7ed108998bda90ccc9a10d4 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 03:14:31 -0800 Subject: [PATCH 097/251] Creates a first simple test for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869124095 Change-Id: Ia9753cdd40d6547dab01a726a30f2fb7459a0b10 --- test/java/common/rules/BUILD | 3 ++ test/java/common/rules/java_runtime_tests.bzl | 41 +++++++++++++++++++ .../testutil/java_runtime_info_subject.bzl | 1 + 3 files changed, 45 insertions(+) create mode 100644 test/java/common/rules/java_runtime_tests.bzl diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 2311a3f2..8a00159d 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -2,6 +2,7 @@ load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") +load(":java_runtime_tests.bzl", "java_runtime_tests") load(":java_test_tests.bzl", "java_test_tests") load(":merge_attrs_tests.bzl", "merge_attrs_test_suite") @@ -17,4 +18,6 @@ java_library_tests(name = "java_library_tests") java_import_tests(name = "java_import_tests") +java_runtime_tests(name = "java_runtime_tests") + java_test_tests(name = "java_test_tests") diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl new file mode 100644 index 00000000..948f0c3b --- /dev/null +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -0,0 +1,41 @@ +"""Tests for the java_runtime rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java/toolchains:java_runtime.bzl", "java_runtime") +load("//test/java/testutil:java_runtime_info_subject.bzl", "java_runtime_info_subject") + +def _test_java_runtime_simple(name): + util.helper_target( + java_runtime, + name = name + "/jvm-foo", + srcs = [ + "foo/a", + "foo/b", + ], + java_home = "foo", + ) + + analysis_test( + name = name, + impl = _test_java_runtime_simple_impl, + target = name + "/jvm-foo", + ) + +def _test_java_runtime_simple_impl(env, target): + java_runtime_info_subject.from_target(env, target).files().contains_exactly([ + "{package}/foo/a", + "{package}/foo/b", + ]) + env.expect.that_target(target).data_runfiles().contains_exactly([ + "{workspace}/{package}/foo/a", + "{workspace}/{package}/foo/b", + ]) + +def java_runtime_tests(name): + test_suite( + name = name, + tests = [ + _test_java_runtime_simple, + ], + ) diff --git a/test/java/testutil/java_runtime_info_subject.bzl b/test/java/testutil/java_runtime_info_subject.bzl index ef5bdf92..37a477eb 100644 --- a/test/java/testutil/java_runtime_info_subject.bzl +++ b/test/java/testutil/java_runtime_info_subject.bzl @@ -14,6 +14,7 @@ def _new_java_runtime_info_subject(java_runtime_info, meta): java_home_runfiles_path = lambda: _new_path_string_subject(self.actual.java_home_runfiles_path, self.meta.derive("java_home_runfiles_path")), java_executable_exec_path = lambda: _new_path_string_subject(self.actual.java_executable_exec_path, self.meta.derive("java_executable_exec_path")), java_executable_runfiles_path = lambda: _new_path_string_subject(self.actual.java_executable_runfiles_path, self.meta.derive("java_executable_runfiles_path")), + files = lambda: subjects.depset_file(self.actual.files, self.meta.derive("files")), ) return public From 4b00962ef9ec1646de06629d1b7940f4d94f945a Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 04:19:22 -0800 Subject: [PATCH 098/251] Creates _test_absolute_java_home_with_srcs for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869144439 Change-Id: Iceebb816a7717371bf23e3f99e3c1d607254993a --- test/java/common/rules/java_runtime_tests.bzl | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index 948f0c3b..deaa1d49 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -1,6 +1,7 @@ """Tests for the java_runtime rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//test/java/testutil:java_runtime_info_subject.bzl", "java_runtime_info_subject") @@ -32,10 +33,31 @@ def _test_java_runtime_simple_impl(env, target): "{workspace}/{package}/foo/b", ]) +def _test_absolute_java_home_with_srcs(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = ["dummy.txt"], + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_srcs_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), + ) + def java_runtime_tests(name): test_suite( name = name, tests = [ _test_java_runtime_simple, + _test_absolute_java_home_with_srcs, ], ) From 5450a510bb236d7d618e2f026415a7ce6ca4d321 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 05:05:00 -0800 Subject: [PATCH 099/251] Creates _test_absolute_java_home_with_java for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869158248 Change-Id: I26ecc40f891cb6dcb0a8443aa94975a52054afe7 --- test/java/common/rules/java_runtime_tests.bzl | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index deaa1d49..12c24022 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -53,11 +53,32 @@ def _test_absolute_java_home_with_srcs_impl(env, target): matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), ) +def _test_absolute_java_home_with_java(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "bin/java", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_java_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_java_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), + ) + def java_runtime_tests(name): test_suite( name = name, tests = [ _test_java_runtime_simple, _test_absolute_java_home_with_srcs, + _test_absolute_java_home_with_java, ], ) From 2d0ba3d072bbf6e81f893cdb7a4d3aa15623a9dc Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 05:27:12 -0800 Subject: [PATCH 100/251] Creates _test_bin_java_path_name for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869165526 Change-Id: Ia89c8e0dd671678e1b687cbb6b349bef02971415 --- test/java/common/rules/java_runtime_tests.bzl | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index 12c24022..94659dd4 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -73,6 +73,25 @@ def _test_absolute_java_home_with_java_impl(env, target): matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), ) +def _test_bin_java_path_name(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "java", + ) + + analysis_test( + name = name, + impl = _test_bin_java_path_name_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_bin_java_path_name_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("the path to 'java' must end in 'bin/java'."), + ) + def java_runtime_tests(name): test_suite( name = name, @@ -80,5 +99,6 @@ def java_runtime_tests(name): _test_java_runtime_simple, _test_absolute_java_home_with_srcs, _test_absolute_java_home_with_java, + _test_bin_java_path_name, ], ) From 281421633bdd3fbcc31e5ce8acd7394371e48ee8 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 05:55:25 -0800 Subject: [PATCH 101/251] Creates _test_absolute_java_home for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869173032 Change-Id: Icdfe10c4f5c01dd6b021bcd3f5da03b2032d78da --- test/java/common/rules/java_runtime_tests.bzl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index 94659dd4..2a2e7545 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -92,6 +92,22 @@ def _test_bin_java_path_name_impl(env, target): matching.str_matches("the path to 'java' must end in 'bin/java'."), ) +def _test_absolute_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_impl, + target = name + "/jvm", + ) + +def _test_absolute_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") + def java_runtime_tests(name): test_suite( name = name, @@ -100,5 +116,6 @@ def java_runtime_tests(name): _test_absolute_java_home_with_srcs, _test_absolute_java_home_with_java, _test_bin_java_path_name, + _test_absolute_java_home, ], ) From 55d2f9a04464ecda289eb0af5ab3d09f25bf5d12 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Feb 2026 06:20:36 -0800 Subject: [PATCH 102/251] Creates _test_relative_java_home for java_runtime() in java_runtime_tests.bzl PiperOrigin-RevId: 869182739 Change-Id: I70bf1e5f83ad908280479938d3c25d45f914220f --- test/java/common/rules/java_runtime_tests.bzl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index 2a2e7545..e23cdf66 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -108,6 +108,22 @@ def _test_absolute_java_home(name): def _test_absolute_java_home_impl(env, target): java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") +def _test_relative_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "b/c", + ) + + analysis_test( + name = name, + impl = _test_relative_java_home_impl, + target = name + "/jvm", + ) + +def _test_relative_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") + def java_runtime_tests(name): test_suite( name = name, @@ -117,5 +133,6 @@ def java_runtime_tests(name): _test_absolute_java_home_with_java, _test_bin_java_path_name, _test_absolute_java_home, + _test_relative_java_home, ], ) From db9b3616d5ce80e5cce7f61ff6c2e6196133a676 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 13 Feb 2026 07:10:08 -0800 Subject: [PATCH 103/251] Creates _test_runtime_alias for java_runtime() in toolchains/java_runtime_tests.bzl PiperOrigin-RevId: 869716975 Change-Id: Ifab9e3a643c66d5815d19c5330ee809ff3ec3e2a --- test/java/toolchains/java_runtime_tests.bzl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index f5014966..2cc617bf 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -135,6 +135,22 @@ def _test_with_generated_java_executable_impl(env, target): assert_info.java_executable_exec_path().starts_with("{bindir}/{package}/foo/bar/bin/java") assert_info.java_executable_runfiles_path().starts_with("{package}/foo/bar/bin/java") +def _test_runtime_alias(name): + util.helper_target( + java_runtime_alias, + name = name + "/alias", + ) + + analysis_test( + name = name, + impl = _test_runtime_alias_impl, + target = name + "/alias", + ) + +def _test_runtime_alias_impl(env, target): + env.expect.that_target(target).has_provider(platform_common.ToolchainInfo) + env.expect.that_target(target).has_provider(platform_common.TemplateVariableInfo) + def java_runtime_tests(name): test_suite( name = name, @@ -142,5 +158,6 @@ def java_runtime_tests(name): _test_with_absolute_java_home, _test_with_hermetic_java_home, _test_with_generated_java_executable, + _test_runtime_alias, ], ) From de9e229c24bd52b61cf98a1bb37b459faf668961 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 13 Feb 2026 07:31:25 -0800 Subject: [PATCH 104/251] Creates _test_runtime_alias for java_runtime() in rules/java_runtime_tests.bzl PiperOrigin-RevId: 869724124 Change-Id: Iaf93555211c88b4a4d94a51abee0c7eec8e83630 --- test/java/common/rules/java_runtime_tests.bzl | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl index e23cdf66..454aa9cd 100644 --- a/test/java/common/rules/java_runtime_tests.bzl +++ b/test/java/common/rules/java_runtime_tests.bzl @@ -124,6 +124,25 @@ def _test_relative_java_home(name): def _test_relative_java_home_impl(env, target): java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") +def _test_java_home_with_invalid_make_variables(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/opt/$(WTF)", + ) + + analysis_test( + name = name, + impl = _test_java_home_with_invalid_make_variables_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_java_home_with_invalid_make_variables_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("$(WTF) not defined"), + ) + def java_runtime_tests(name): test_suite( name = name, @@ -134,5 +153,6 @@ def java_runtime_tests(name): _test_bin_java_path_name, _test_absolute_java_home, _test_relative_java_home, + _test_java_home_with_invalid_make_variables, ], ) From eaf868ea2ad1177836ff1178f03408f6371a27a2 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 16 Feb 2026 00:50:06 -0800 Subject: [PATCH 105/251] Move java_runtime tests to the toolchains directory. The tests for the `java_runtime` rule are now located in `test/java/toolchains/java_runtime_tests.bzl`, aligning with the location of the `java_runtime` rule itself. PiperOrigin-RevId: 870739029 Change-Id: I56d58653eb9e9b8ed700adad7a9fce7750ae1645 --- test/java/common/rules/BUILD | 3 - test/java/common/rules/java_runtime_tests.bzl | 158 ------------------ test/java/toolchains/java_runtime_tests.bzl | 145 ++++++++++++++++ 3 files changed, 145 insertions(+), 161 deletions(-) delete mode 100644 test/java/common/rules/java_runtime_tests.bzl diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 8a00159d..2311a3f2 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -2,7 +2,6 @@ load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") -load(":java_runtime_tests.bzl", "java_runtime_tests") load(":java_test_tests.bzl", "java_test_tests") load(":merge_attrs_tests.bzl", "merge_attrs_test_suite") @@ -18,6 +17,4 @@ java_library_tests(name = "java_library_tests") java_import_tests(name = "java_import_tests") -java_runtime_tests(name = "java_runtime_tests") - java_test_tests(name = "java_test_tests") diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl deleted file mode 100644 index 454aa9cd..00000000 --- a/test/java/common/rules/java_runtime_tests.bzl +++ /dev/null @@ -1,158 +0,0 @@ -"""Tests for the java_runtime rule""" - -load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") -load("@rules_testing//lib:truth.bzl", "matching") -load("@rules_testing//lib:util.bzl", "util") -load("//java/toolchains:java_runtime.bzl", "java_runtime") -load("//test/java/testutil:java_runtime_info_subject.bzl", "java_runtime_info_subject") - -def _test_java_runtime_simple(name): - util.helper_target( - java_runtime, - name = name + "/jvm-foo", - srcs = [ - "foo/a", - "foo/b", - ], - java_home = "foo", - ) - - analysis_test( - name = name, - impl = _test_java_runtime_simple_impl, - target = name + "/jvm-foo", - ) - -def _test_java_runtime_simple_impl(env, target): - java_runtime_info_subject.from_target(env, target).files().contains_exactly([ - "{package}/foo/a", - "{package}/foo/b", - ]) - env.expect.that_target(target).data_runfiles().contains_exactly([ - "{workspace}/{package}/foo/a", - "{workspace}/{package}/foo/b", - ]) - -def _test_absolute_java_home_with_srcs(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - srcs = ["dummy.txt"], - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_with_srcs_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_absolute_java_home_with_srcs_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), - ) - -def _test_absolute_java_home_with_java(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java = "bin/java", - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_with_java_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_absolute_java_home_with_java_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), - ) - -def _test_bin_java_path_name(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java = "java", - ) - - analysis_test( - name = name, - impl = _test_bin_java_path_name_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_bin_java_path_name_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("the path to 'java' must end in 'bin/java'."), - ) - -def _test_absolute_java_home(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_impl, - target = name + "/jvm", - ) - -def _test_absolute_java_home_impl(env, target): - java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") - -def _test_relative_java_home(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "b/c", - ) - - analysis_test( - name = name, - impl = _test_relative_java_home_impl, - target = name + "/jvm", - ) - -def _test_relative_java_home_impl(env, target): - java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") - -def _test_java_home_with_invalid_make_variables(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "/opt/$(WTF)", - ) - - analysis_test( - name = name, - impl = _test_java_home_with_invalid_make_variables_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_java_home_with_invalid_make_variables_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("$(WTF) not defined"), - ) - -def java_runtime_tests(name): - test_suite( - name = name, - tests = [ - _test_java_runtime_simple, - _test_absolute_java_home_with_srcs, - _test_absolute_java_home_with_java, - _test_bin_java_path_name, - _test_absolute_java_home, - _test_relative_java_home, - _test_java_home_with_invalid_make_variables, - ], - ) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 2cc617bf..a32c3a99 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -1,6 +1,7 @@ """Tests for the java_runtime rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") @@ -151,6 +152,143 @@ def _test_runtime_alias_impl(env, target): env.expect.that_target(target).has_provider(platform_common.ToolchainInfo) env.expect.that_target(target).has_provider(platform_common.TemplateVariableInfo) +def _test_java_runtime_simple(name): + util.helper_target( + java_runtime, + name = name + "/jvm-foo", + srcs = [ + "foo/a", + "foo/b", + ], + java_home = "foo", + ) + + analysis_test( + name = name, + impl = _test_java_runtime_simple_impl, + target = name + "/jvm-foo", + ) + +def _test_java_runtime_simple_impl(env, target): + java_runtime_info_subject.from_target(env, target).files().contains_exactly([ + "{package}/foo/a", + "{package}/foo/b", + ]) + env.expect.that_target(target).data_runfiles().contains_exactly([ + "{workspace}/{package}/foo/a", + "{workspace}/{package}/foo/b", + ]) + +def _test_absolute_java_home_with_srcs(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = ["dummy.txt"], + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_srcs_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), + ) + +def _test_absolute_java_home_with_java(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "bin/java", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_java_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_java_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), + ) + +def _test_bin_java_path_name(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "java", + ) + + analysis_test( + name = name, + impl = _test_bin_java_path_name_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_bin_java_path_name_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("the path to 'java' must end in 'bin/java'."), + ) + +def _test_absolute_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_impl, + target = name + "/jvm", + ) + +def _test_absolute_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") + +def _test_relative_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "b/c", + ) + + analysis_test( + name = name, + impl = _test_relative_java_home_impl, + target = name + "/jvm", + ) + +def _test_relative_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") + +def _test_java_home_with_invalid_make_variables(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/opt/$(WTF)", + ) + + analysis_test( + name = name, + impl = _test_java_home_with_invalid_make_variables_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_java_home_with_invalid_make_variables_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("$(WTF) not defined"), + ) + def java_runtime_tests(name): test_suite( name = name, @@ -159,5 +297,12 @@ def java_runtime_tests(name): _test_with_hermetic_java_home, _test_with_generated_java_executable, _test_runtime_alias, + _test_java_runtime_simple, + _test_absolute_java_home_with_srcs, + _test_absolute_java_home_with_java, + _test_bin_java_path_name, + _test_absolute_java_home, + _test_relative_java_home, + _test_java_home_with_invalid_make_variables, ], ) From d6d662848ecdbd874d9ed351e3c072997c0ced2b Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 16 Feb 2026 04:11:31 -0800 Subject: [PATCH 106/251] Internal change PiperOrigin-RevId: 870821103 Change-Id: I7890323adef19ec859bbbcb64ce8ddcd2c833bb6 --- java/private/java_common.bzl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 3c11c0e8..6d877d76 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl @@ -299,7 +299,6 @@ def _make_java_common(): "default_javac_opts": _default_javac_opts, "default_javac_opts_depset": _default_javac_opts_depset, "merge": _merge, - "make_non_strict": _make_non_strict, "JavaPluginInfo": JavaPluginInfo, "JavaToolchainInfo": JavaToolchainInfo, "JavaRuntimeInfo": JavaRuntimeInfo, @@ -314,6 +313,10 @@ def _make_java_common(): set_annotation_processing = _set_annotation_processing, java_toolchain_label = _java_toolchain_label, ) + if semantics.IS_BAZEL: + methods.update( + make_non_strict = _make_non_strict, + ) return struct(**methods) java_common = _make_java_common() From 5265486294c2a0f5269495424a5df9ad569cc543 Mon Sep 17 00:00:00 2001 From: hvadehra Date: Tue, 17 Feb 2026 05:56:40 -0800 Subject: [PATCH 107/251] Add releasing and publish-to-bcr workflows (#351) Work towards https://github.com/bazelbuild/rules_java/issues/307 Closes #351 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/351 from bazelbuild:hvd_gh_release 8a853c71d68ed1ff8c32ea1187ae81b046c422b7 PiperOrigin-RevId: 871272493 Change-Id: I18daeeddd75f73b936de1a7dd0d3e2c7b8b09b9b --- .github/workflows/publish.yaml | 32 +++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 27 ++++++++++++++++++++++++++ .github/workflows/release_prep.sh | 17 ++++++++++++++++ MODULE.bazel | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/release.yaml create mode 100755 .github/workflows/release_prep.sh diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..3652a521 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,32 @@ +name: Publish to BCR +on: + # Run the publish workflow after a successful release + # Will be triggered from the release.yaml workflow + workflow_call: + inputs: + tag_name: + required: true + type: string + # Permit release engineers to retry manually from the GitHub UI + workflow_dispatch: + inputs: + tag_name: + description: git tag being released + required: true + type: string +jobs: + publish: + uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.1.0 + with: + tag_name: ${{ inputs.tag_name }} + # GitHub repository which is a fork of the upstream where the Pull Request will be opened. + registry_fork: bazel-io/bazel-central-registry + draft: false + attest: true + permissions: + contents: write + id-token: write + attestations: write + secrets: + # Necessary to push to the BCR fork, and to open a pull request against a registry + publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..29c7bfbb --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,27 @@ +# Automatically perform a release whenever a new "release-like" tag is pushed to the repo. +name: Release + +on: + push: + tags: + # Detect tags that look like a release. + - "*.*.*" +permissions: + id-token: write + attestations: write + contents: write +jobs: + release: + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.2.3 + with: + tag_name: ${{ github.ref_name }} + prerelease: false + draft: false + generate_release_notes: true + release_files: bazel-bin/distro/rules_java-*.tar.gz + bazel_test_command: "bazel test //test/... -//test:docs_up_to_date_test" + publish: + needs: release + uses: ./.github/workflows/publish.yaml + with: + tag_name: ${{ github.ref_name }} diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100755 index 00000000..3173376a --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +RELEASE_VERSION=${1} + +# update MODULE.bazel with the version number +sed -i "3s/version = \"0.0.0\"/version = \"${RELEASE_VERSION}\"/" MODULE.bazel + +# create release artifacts +bazel build //distro:relnotes //distro:rules_java-${RELEASE_VERSION}.tar.gz + +# revert change to MODULE.bazel +git checkout -- MODULE.bazel + +# print the release notes for release.yaml +cat bazel-bin/distro/relnotes.txt diff --git a/MODULE.bazel b/MODULE.bazel index 70e975f3..47354f67 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_java", - version = "9.5.0", + version = "0.0.0", bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) From 188850bf0b98b4f2b8084f0b9f508c542b1dcba9 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 17 Feb 2026 06:58:08 -0800 Subject: [PATCH 108/251] `JavaStarlarkApiTest`: starlarkify `javaInfoConstructorWithNeverlink` This seems like a pretty trivial test. Do we even need it? Should I consider appropriate coverage or is that out of scope of the "Starlarkify the coverage we already have" task? PiperOrigin-RevId: 871294944 Change-Id: I404acea5e0734ee7f7cb83b1c932d096f9937cbe --- test/java/common/java_info_tests.bzl | 19 +++++++++++++++++++ test/java/testutil/java_info_subject.bzl | 1 + 2 files changed, 20 insertions(+) diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index a646e112..ce82df2b 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -1261,6 +1261,24 @@ def _output_source_jars_returns_depset_test_impl(env, target): source_jars = target[JavaInfo].java_outputs[0].source_jars env.expect.that_str(type(source_jars)).equals(type(depset())) +def _java_info_constructor_with_neverlink_test(name): + target_name = name + "/my_starlark_rule" + util.helper_target( + custom_java_info_rule, + name = target_name, + output_jar = target_name + "/my_starlark_rule_lib.jar", + neverlink = True, + ) + + analysis_test( + name = name, + impl = _java_info_constructor_with_neverlink_test_impl, + target = target_name, + ) + +def _java_info_constructor_with_neverlink_test_impl(env, target): + java_info_subject.from_target(env, target).is_neverlink().equals(True) + def java_info_tests(name): test_suite( name = name, @@ -1305,5 +1323,6 @@ def java_info_tests(name): _annotation_processing_test, _compilation_info_test, _output_source_jars_returns_depset_test, + _java_info_constructor_with_neverlink_test, ], ) diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index e0ec8059..8471706f 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -27,6 +27,7 @@ def _new_java_info_subject(java_info, meta): transitive_source_jars_list = lambda: subjects.collection(java_info.transitive_source_jars.to_list(), self.meta.derive("transitive_source_jars.to_list()")), runtime_output_jars = lambda: subjects.depset_file(java_info.runtime_output_jars, self.meta.derive("runtime_output_jars")), module_flags = lambda: _new_java_module_flags_subject(self.actual, self.meta), + is_neverlink = lambda: subjects.bool(getattr(java_info, "_neverlink", False), self.meta.derive("_neverlink")), ) return public From 6710ecd8efdea80d8b0da92db5b699202343c2e7 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 18 Feb 2026 05:51:22 -0800 Subject: [PATCH 109/251] Creates _test_make_variables for java_runtime() in toolchains/java_runtime_tests.bzl PiperOrigin-RevId: 871826344 Change-Id: I787659e6082a48e0e7a7003e1ae47bc66fd3fa83 --- MODULE.bazel | 6 +++--- test/java/toolchains/java_runtime_tests.bzl | 24 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 47354f67..de8fe111 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -131,9 +131,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-0+3pLjeZCqn+K1qS7HNr7HbwMXBjxLvJm+pMSUhDel8=", - strip_prefix = "rules_testing-db007bfee840cebcb6f955b80973ba866de38947", - urls = ["https://github.com/bazelbuild/rules_testing/archive/db007bfee840cebcb6f955b80973ba866de38947.tar.gz"], + integrity = "sha256-TqwTCQnzt/hRKQtdJ7d8ebtZ8+I8IMgmWiEjOKvo6mI=", + strip_prefix = "rules_testing-f8e869d452507fa4a59748c9d69cfab63ec9385a", + urls = ["https://github.com/bazelbuild/rules_testing/archive/f8e869d452507fa4a59748c9d69cfab63ec9385a.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index a32c3a99..a1865140 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -1,7 +1,7 @@ """Tests for the java_runtime rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") -load("@rules_testing//lib:truth.bzl", "matching") +load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") @@ -289,6 +289,27 @@ def _test_java_home_with_invalid_make_variables_impl(env, target): matching.str_matches("$(WTF) not defined"), ) +def _test_make_variables(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/foo/bar", + ) + + analysis_test( + name = name, + impl = _test_make_variables_impl, + target = name + "/jvm", + ) + +def _test_make_variables_impl(env, target): + env.expect.that_target(target).provider( + platform_common.TemplateVariableInfo, + ).variables().contains_at_least({"JAVABASE": "/foo/bar"}) + env.expect.that_target(target).provider( + platform_common.TemplateVariableInfo, + ).variables().get("JAVA", factory = subjects.str).starts_with("/foo/bar/bin/java") + def java_runtime_tests(name): test_suite( name = name, @@ -304,5 +325,6 @@ def java_runtime_tests(name): _test_absolute_java_home, _test_relative_java_home, _test_java_home_with_invalid_make_variables, + _test_make_variables, ], ) From 4b4390839f3b838d9a846af1ba020bb1de61b4aa Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 18 Feb 2026 07:27:40 -0800 Subject: [PATCH 110/251] Creates _test_no_srcs for java_runtime() in toolchains/java_runtime_tests.bzl PiperOrigin-RevId: 871861263 Change-Id: I8fc85bb0970576b0e3e9bdecec2fb4a0c27f168f --- test/java/toolchains/java_runtime_tests.bzl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index a1865140..8efa5d2f 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -310,6 +310,24 @@ def _test_make_variables_impl(env, target): platform_common.TemplateVariableInfo, ).variables().get("JAVA", factory = subjects.str).starts_with("/foo/bar/bin/java") +def _test_no_srcs(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/opt/jvm", + ) + + analysis_test( + name = name, + impl = _test_no_srcs_impl, + target = name + "/jvm", + ) + +def _test_no_srcs_impl(env, target): + assert_info = java_runtime_info_subject.from_target(env, target) + assert_info.java_home().equals("/opt/jvm") + assert_info.files().contains_exactly([]) + def java_runtime_tests(name): test_suite( name = name, @@ -326,5 +344,6 @@ def java_runtime_tests(name): _test_relative_java_home, _test_java_home_with_invalid_make_variables, _test_make_variables, + _test_no_srcs, ], ) From 3ed922825db30a419b8c8487d5b3b8e1533d0303 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 18 Feb 2026 08:32:54 -0800 Subject: [PATCH 111/251] `JavaStarlarkApiTest`: starlarkify neverlink, native lib tests. PiperOrigin-RevId: 871885265 Change-Id: I3b50a3a2e18391741e745b258fa343fa5ba2385d --- test/java/common/java_info_tests.bzl | 118 +++++++++++++++++- test/java/common/rules/java_library_tests.bzl | 2 - test/java/testutil/rules/java_info_merge.bzl | 17 +++ 3 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 test/java/testutil/rules/java_info_merge.bzl diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index ce82df2b..4f82d3eb 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -10,7 +10,9 @@ load("//java/common:java_info.bzl", "JavaInfo") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:rules/bad_java_info_rules.bzl", "bad_deps", "bad_exports", "bad_libs", "bad_runtime_deps", "compile_jar_not_set", "compile_jar_set_to_none") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") +load("//test/java/testutil:rules/custom_library.bzl", "custom_library") load("//test/java/testutil:rules/forward_java_info.bzl", "java_info_forwarding_rule") +load("//test/java/testutil:rules/java_info_merge.bzl", "java_info_merge_rule") def _with_output_jar_only_test(name): target_name = name + "/my_starlark_rule" @@ -168,8 +170,6 @@ def _with_native_libraries_test(name): name = name, impl = _with_native_libraries_test_impl, target = target_name, - # LibraryToLink.library_indentifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _with_native_libraries_test_impl(env, target): @@ -1279,6 +1279,117 @@ def _java_info_constructor_with_neverlink_test(name): def _java_info_constructor_with_neverlink_test_impl(env, target): java_info_subject.from_target(env, target).is_neverlink().equals(True) +def _java_common_merge_with_neverlink_test(name): + target_name = name + "/merged" + util.helper_target( + custom_java_info_rule, + name = target_name + "/with_neverlink", + output_jar = target_name + "/with_neverlink.jar", + neverlink = True, + ) + util.helper_target( + custom_java_info_rule, + name = target_name + "/without_neverlink", + output_jar = target_name + "/without_neverlink.jar", + neverlink = False, + ) + util.helper_target( + java_info_merge_rule, + name = target_name, + deps = [target_name + "/with_neverlink", target_name + "/without_neverlink"], + ) + + analysis_test( + name = name, + impl = _java_common_merge_with_neverlink_test_impl, + target = target_name, + ) + +def _java_common_merge_with_neverlink_test_impl(env, target): + java_info_subject.from_target(env, target).is_neverlink().equals(True) + +def _java_common_compile_with_neverlink_test(name): + target_name = name + "/compiled" + util.helper_target( + custom_library, + name = target_name, + srcs = ["A.java"], + neverlink = True, + ) + + analysis_test( + name = name, + impl = _java_common_compile_with_neverlink_test_impl, + target = target_name, + ) + +def _java_common_compile_with_neverlink_test_impl(env, target): + java_info_subject.from_target(env, target).is_neverlink().equals(True) + +# Tests that java_common.compile propagates native libraries from deps, +# runtime_deps, and exports. +def _java_common_compile_native_libraries_propagate_test(name): + target_name = name + "/compiled" + + util.helper_target( + cc_library, + name = target_name + "/native_dep", + srcs = ["a.cc"], + ) + util.helper_target( + java_library, + name = target_name + "/lib_dep", + srcs = ["B.java"], + deps = [target_name + "/native_dep"], + ) + + util.helper_target( + cc_library, + name = target_name + "/native_rdep", + srcs = ["c.cc"], + ) + util.helper_target( + java_library, + name = target_name + "/lib_rdep", + srcs = ["D.java"], + deps = [target_name + "/native_rdep"], + ) + + util.helper_target( + cc_library, + name = target_name + "/native_export", + srcs = ["e.cc"], + ) + util.helper_target( + java_library, + name = target_name + "/lib_export", + srcs = ["F.java"], + deps = [target_name + "/native_export"], + ) + + util.helper_target( + custom_library, + name = target_name, + srcs = ["G.java"], + deps = [target_name + "/lib_dep"], + runtime_deps = [target_name + "/lib_rdep"], + exports = [target_name + "/lib_export"], + ) + + analysis_test( + name = name, + impl = _java_common_compile_native_libraries_propagate_test_impl, + target = target_name, + ) + +def _java_common_compile_native_libraries_propagate_test_impl(env, target): + assert_native_libs = java_info_subject.from_target(env, target).transitive_native_libraries() + assert_native_libs.static_libraries().contains_exactly_predicates([ + matching.str_matches("*native_rdep*"), + matching.str_matches("*native_export*"), + matching.str_matches("*native_dep*"), + ]) + def java_info_tests(name): test_suite( name = name, @@ -1324,5 +1435,8 @@ def java_info_tests(name): _compilation_info_test, _output_source_jars_returns_depset_test, _java_info_constructor_with_neverlink_test, + _java_common_merge_with_neverlink_test, + _java_common_compile_with_neverlink_test, + _java_common_compile_native_libraries_propagate_test, ], ) diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index 58a282f9..c6bb282a 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -267,8 +267,6 @@ def _test_propagates_direct_native_libraries(name): name = name, impl = _test_propagates_direct_native_libraries_impl, target = target_name, - # LibraryToLink.library_indentifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_propagates_direct_native_libraries_impl(env, target): diff --git a/test/java/testutil/rules/java_info_merge.bzl b/test/java/testutil/rules/java_info_merge.bzl new file mode 100644 index 00000000..e31201d9 --- /dev/null +++ b/test/java/testutil/rules/java_info_merge.bzl @@ -0,0 +1,17 @@ +"""Helper rule for testing java_common.merge""" + +load("//java/common:java_common.bzl", "java_common") +load("//java/common:java_info.bzl", "JavaInfo") + +def _impl(ctx): + java_infos = [dep[JavaInfo] for dep in ctx.attr.deps] + merged_info = java_common.merge(java_infos) + return [merged_info] + +java_info_merge_rule = rule( + implementation = _impl, + attrs = { + "deps": attr.label_list(providers = [JavaInfo]), + }, + provides = [JavaInfo], +) From 4586a5bb4278d625922a3fb3f87b06fecf93ceda Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 19 Feb 2026 00:52:33 -0800 Subject: [PATCH 112/251] Creates _test_java_home_generated for java_runtime() in toolchains/java_runtime_tests.bzl PiperOrigin-RevId: 872258802 Change-Id: I812815c2aa1c0b3671f7661f5fec358f2029a9c8 --- .../testutil/java_runtime_info_subject.bzl | 1 + test/java/toolchains/java_runtime_tests.bzl | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/test/java/testutil/java_runtime_info_subject.bzl b/test/java/testutil/java_runtime_info_subject.bzl index 37a477eb..ad68fead 100644 --- a/test/java/testutil/java_runtime_info_subject.bzl +++ b/test/java/testutil/java_runtime_info_subject.bzl @@ -41,6 +41,7 @@ def _from_target(env, target): "name": target.label.name, "package": target.label.package, "bindir": target[TestingAspectInfo].bin_path, + "gendir": env.ctx.configuration.genfiles_dir.path, }, ), ) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 8efa5d2f..5ec2a061 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -328,6 +328,31 @@ def _test_no_srcs_impl(env, target): assert_info.java_home().equals("/opt/jvm") assert_info.files().contains_exactly([]) +def _test_java_home_generated(name): + util.helper_target( + native.genrule, + name = name + "/gen", + outs = ["generated_java_home/bin/java"], + cmd = "touch $@", + ) + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "generated_java_home/bin/java", + java_home = "generated_java_home", + ) + + analysis_test( + name = name, + impl = _test_java_home_generated_impl, + target = name + "/jvm", + ) + +def _test_java_home_generated_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals( + "{gendir}/{package}/generated_java_home", + ) + def java_runtime_tests(name): test_suite( name = name, @@ -345,5 +370,6 @@ def java_runtime_tests(name): _test_java_home_with_invalid_make_variables, _test_make_variables, _test_no_srcs, + _test_java_home_generated, ], ) From 2e5f415c8ff81763efa0bdd4cb2dd6a20ee19381 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 02:09:50 -0800 Subject: [PATCH 113/251] Update to `release_ruleset.yaml` `v7.3.0` PiperOrigin-RevId: 873950161 Change-Id: I96843bcdfa95bc8d68f1629c75eaee7a85793326 --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 29c7bfbb..2bd13f25 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,7 +12,7 @@ permissions: contents: write jobs: release: - uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.2.3 + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.3.0 with: tag_name: ${{ github.ref_name }} prerelease: false From 03a8aed7e18ff28bd8a218505f9b05f160ba81ca Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 03:45:04 -0800 Subject: [PATCH 114/251] Clean up references to disabled test PiperOrigin-RevId: 873985222 Change-Id: Ie7bfadfc788830da6a4e5a98139f2a7949e2de2e --- .bazelci/presubmit.yml | 4 ---- .github/workflows/release.yaml | 2 +- test/BUILD.bazel | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 411f490c..704e6eb1 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -10,9 +10,7 @@ build_targets: &build_targets - "@remote_java_tools//:singlejar_cc_bin" # can't build @remote_java_tools_X repos for other platforms - "-//toolchains/..." - # TODO: re-enable docs after moving them out of https://bazel.build/reference/be/java - "-//java/docs/..." - - "-//test:docs_up_to_date_test" build_targets_integration: &build_targets_integration - "//..." @@ -20,8 +18,6 @@ build_targets_integration: &build_targets_integration test_targets: &test_targets - "//test/..." - # TODO: re-enable docs after moving them out of https://bazel.build/reference/be/java - - "-//test:docs_up_to_date_test" test_target_integration: &test_target_integration - "//:MyTest" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2bd13f25..06ee719b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,7 @@ jobs: draft: false generate_release_notes: true release_files: bazel-bin/distro/rules_java-*.tar.gz - bazel_test_command: "bazel test //test/... -//test:docs_up_to_date_test" + bazel_test_command: "bazel test -- //test/..." publish: needs: release uses: ./.github/workflows/publish.yaml diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 951280d6..fdc241fb 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -72,6 +72,8 @@ diff_test( """, file1 = "//java/docs:rules.md", file2 = "//java/docs:rules_docs", + # TODO: b/369123329 - re-enable docs after moving them out of https://bazel.build/reference/be/java + tags = ["manual"], ) validate_configs() From d3280ec2fa55739f45205fc25683c9a67d37b450 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 04:52:32 -0800 Subject: [PATCH 115/251] Fix workflow test command The reusable workflow adds flags after our command so we can't use `--` PiperOrigin-RevId: 874008604 Change-Id: Ia46f2639620566509599ea5362b1ac3f0fcaed74 --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 06ee719b..dcd3d167 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,7 @@ jobs: draft: false generate_release_notes: true release_files: bazel-bin/distro/rules_java-*.tar.gz - bazel_test_command: "bazel test -- //test/..." + bazel_test_command: "bazel test //test/..." publish: needs: release uses: ./.github/workflows/publish.yaml From ddcdff8a6c948a6624a3af33e6da2cbd2d13fcf9 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 06:28:15 -0800 Subject: [PATCH 116/251] Fix publish workflow Secrets are not passed to reusable workflows by default. Ref: https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows#passing-inputs-and-secrets-to-a-reusable-workflow PiperOrigin-RevId: 874040719 Change-Id: Icca60ffc830c576b165d389eaaab3b49a17f137c --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dcd3d167..4bfb5090 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -25,3 +25,4 @@ jobs: uses: ./.github/workflows/publish.yaml with: tag_name: ${{ github.ref_name }} + secrets: inherit From f31c1a8818dd75775353d884bec604b18ee66697 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 08:16:19 -0800 Subject: [PATCH 117/251] Starlarkify JavaToolchainTest.javac_getsOptionsFromToolchain() PiperOrigin-RevId: 874081635 Change-Id: Ie56e4c40878e781e130a229b60bf2e7bdf0386c3 --- test/java/testutil/javac_action_subject.bzl | 19 +++- test/java/toolchains/java_toolchain_tests.bzl | 93 +++++++++++++++++-- 2 files changed, 98 insertions(+), 14 deletions(-) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 0a14c777..ef23812c 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -4,10 +4,10 @@ load("@rules_testing//lib:truth.bzl", "subjects", "truth") load("@rules_testing//lib:util.bzl", "TestingAspectInfo") def _new_javac_action_subject(env, target, output): - action = env.expect.that_target(target).action_generating(output).actual + action_subject = env.expect.that_target(target).action_generating(output) self = struct( - actual = action, - parsed_flags = _parse_flags(action.argv), + actual = action_subject.actual, + parsed_flags = _parse_flags(action_subject.actual.argv), meta = truth.expect(env).meta.derive( "Javac", format_str_kwargs = { @@ -17,8 +17,15 @@ def _new_javac_action_subject(env, target, output): }, ), ) + public = struct( - direct_dependencies = lambda: subjects.collection(self.parsed_flags["--direct_dependencies"], self.meta.derive("--direct_dependencies"), format = True), + direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), + source = lambda: _create_subject_for_flag("-source", self.parsed_flags, self.meta), + target = lambda: _create_subject_for_flag("-target", self.parsed_flags, self.meta), + xmaxerrs = lambda: _create_subject_for_flag("-Xmaxerrs", self.parsed_flags, self.meta), + jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), + inputs = action_subject.inputs, + argv = action_subject.argv, ) return public @@ -43,6 +50,10 @@ def _parse_flags(argv): return flag_values +def _create_subject_for_flag(flag_name, parsed_flags, meta): + """Helper to create a collection subject for a given flag.""" + return subjects.collection(parsed_flags[flag_name], meta.derive(flag_name), format = True) + javac_action_subject = struct( of = _new_javac_action_subject, parse_flags = _parse_flags, # exposed for testing this method itself diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 928ce00b..976bb082 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -2,28 +2,100 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") +load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//java/toolchains:java_toolchain.bzl", "java_toolchain") load("//test/java/testutil:java_toolchain_info_subject.bzl", "java_toolchain_info_subject") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") def _declare_java_toolchain(*, name, **kwargs): - if "java_runtime" not in kwargs: - kwargs["java_runtime"] = name + "/runtime" - java_runtime(name = name + "/runtime") + java_runtime_name = name + "/runtime" + java_runtime(name = java_runtime_name) + toolchain_attrs = { + "source_version": "6", + "target_version": "6", + "bootclasspath": ["rt.jar"], + "xlint": ["toto"], + "javacopts": ["-Xmaxerrs 500"], + "compatible_javacopts": { + "android": ["-XDandroidCompatible"], + "testonly": ["-XDtestOnly"], + "public_visibility": ["-XDpublicVisibility"], + }, + "tools": [":javac_canary.jar"], + "javabuilder": ":JavaBuilder_deploy.jar", + "header_compiler": ":turbine_canary_deploy.jar", + "header_compiler_direct": ":turbine_direct", + "singlejar": "singlejar", + "ijar": "ijar", + "genclass": "GenClass_deploy.jar", + "timezone_data": "tzdata.jar", + "header_compiler_builtin_processors": ["BuiltinProc1", "BuiltinProc2"], + "reduced_classpath_incompatible_processors": [ + "IncompatibleProc1", + "IncompatibleProc2", + ], + "java_runtime": java_runtime_name, + } + toolchain_attrs.update(kwargs) util.helper_target( java_toolchain, + name = name + "/java_toolchain", + **toolchain_attrs + ) + util.helper_target( + native.toolchain, + name = name + "/toolchain", + toolchain = name + "/java_toolchain", + toolchain_type = semantics.JAVA_TOOLCHAIN_TYPE, + ) + +def _test_javac_gets_options(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["b.java"], + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + deps = [Label(name + "/b")], + ) + + analysis_test( name = name, - genclass = kwargs.get("genclass", "default_genclass.jar"), - jacocorunner = kwargs.get("jacocorunner", None), - javabuilder = kwargs.get("javabuilder", "default_javabuilder.jar"), - java_runtime = kwargs["java_runtime"], - ijar = kwargs.get("ijar", "default_ijar.jar"), - singlejar = kwargs.get("singlejar", "default_singlejar.jar"), + impl = _test_javac_gets_options_impl, + targets = { + "a": name + "/a", + "b": name + "/b", + }, + config_settings = { + "//command_line_option:java_header_compilation": "true", + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) +def _test_javac_gets_options_impl(env, targets): + assert_javac_action = javac_action_subject.of(env, targets.a, "{package}/lib{name}.jar") + assert_javac_action.source().contains_exactly(["6"]) + assert_javac_action.target().contains_exactly(["6"]) + assert_javac_action.xmaxerrs().contains_exactly(["500"]) + assert_javac_action.jar().contains_exactly(["{package}/JavaBuilder_deploy.jar"]) + assert_javac_action.inputs().contains("{package}/rt.jar") + + assert_argv = assert_javac_action.argv() + assert_argv.contains("-Xlint:toto") + assert_argv.not_contains("-g") + + assert_header_action = javac_action_subject.of(env, targets.b, "{package}/lib{name}-hjar.jar") + assert_header_action.argv().contains("{package}/turbine_direct") + def _test_jacocorunner(name): _declare_java_toolchain( - name = name + "/java_toolchain", + name = name, jacocorunner = "myjacocorunner.jar", ) @@ -43,5 +115,6 @@ def java_toolchain_tests(name): name = name, tests = [ _test_jacocorunner, + _test_javac_gets_options, ], ) From 737f145f16decfae668f07448dcd479686dd3865 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Feb 2026 10:09:22 -0800 Subject: [PATCH 118/251] Migrate JavaPluginConfiguredTargetTest to Starlark. This deletes and does not replace TestNoConstraintsAttribute, because it checks for a loading phase error. PiperOrigin-RevId: 874134416 Change-Id: I8e18dc44c391fd7ec4832adf4576778af5bb333a --- test/java/common/rules/java_plugin_tests.bzl | 304 +++++++++++++++++++ 1 file changed, 304 insertions(+) diff --git a/test/java/common/rules/java_plugin_tests.bzl b/test/java/common/rules/java_plugin_tests.bzl index 646de647..71c2d156 100644 --- a/test/java/common/rules/java_plugin_tests.bzl +++ b/test/java/common/rules/java_plugin_tests.bzl @@ -1,10 +1,12 @@ """Tests for the java_plugin rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_plugin_info.bzl", "JavaPluginInfo") +load("//java/common:proguard_spec_info.bzl", "ProguardSpecInfo") load("//test/java/testutil:java_info_subject.bzl", "java_plugin_info_subject") def _test_exposes_plugins_to_starlark(name): @@ -75,11 +77,313 @@ def _test_exposes_api_generating_plugins_to_starlark_impl(env, target): assert_api_plugin_data.processor_data().contains_exactly(["{package}/pluginfile.dat"]) assert_api_plugin_data.equals(target[JavaPluginInfo].plugins) +def _test_not_empty_processor_class(name): + util.helper_target( + java_library, + name = name + "/deps", + srcs = ["Deps.java"], + ) + util.helper_target( + java_plugin, + name = name + "/processor", + srcs = ["Processor.java"], + processor_class = "com.google.test.Processor", + deps = [name + "/deps"], + ) + + analysis_test( + name = name, + impl = _test_not_empty_processor_class_impl, + target = name + "/processor", + ) + +def _test_not_empty_processor_class_impl(env, target): + plugin_info = java_plugin_info_subject.from_target(env, target) + plugin_info.plugins().processor_classes().contains_exactly(["com.google.test.Processor"]) + + plugin_info.plugins().processor_jars().contains_exactly([ + "{package}/lib{name}.jar", + "{package}/lib{test_name}/deps.jar", + ]) + +def _test_empty_processor_class(name): + util.helper_target( + java_library, + name = name + "/deps", + srcs = ["Deps.java"], + ) + util.helper_target( + java_plugin, + name = name + "/bugchecker", + srcs = ["BugChecker.java"], + deps = [":" + name + "/deps"], + ) + + analysis_test( + name = name, + impl = _test_empty_processor_class_impl, + target = name + "/bugchecker", + ) + +def _test_empty_processor_class_impl(env, target): + plugin_info = java_plugin_info_subject.from_target(env, target) + plugin_info.plugins().processor_classes().contains_exactly([]) + plugin_info.plugins().processor_jars().contains_exactly([ + "{package}/lib{name}.jar", + "{package}/lib{test_name}/deps.jar", + ]) + +def _test_empty_processor_class_target(name): + util.helper_target( + java_library, + name = name + "/deps", + srcs = ["Deps.java"], + ) + util.helper_target( + java_plugin, + name = name + "/bugchecker", + srcs = ["BugChecker.java"], + deps = [":" + name + "/deps"], + ) + util.helper_target( + java_library, + name = name + "/empty", + plugins = [":" + name + "/bugchecker"], + ) + + analysis_test( + name = name, + impl = _test_empty_processor_class_target_impl, + target = name + "/empty", + ) + +def _test_empty_processor_class_target_impl(env, target): + env.expect.that_target(target).action_generating("{package}/lib{name}.jar").inputs().contains_at_least([ + "{package}/lib{test_name}/bugchecker.jar", + "{package}/lib{test_name}/deps.jar", + ]) + +def _new_proguard_info_subject(info, meta): + return struct( + specs = lambda: subjects.depset_file(info.specs, meta.derive("specs")), + ) + +def _test_java_plugin_exports_transitive_proguard_specs(name): + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + proguard_specs = ["plugin.pro"], + ) + util.helper_target( + java_library, + name = name + "/dep", + srcs = ["Dep.java"], + proguard_specs = ["dep.pro"], + ) + util.helper_target( + java_plugin, + name = name + "/top", + srcs = ["Top.java"], + plugins = [":" + name + "/plugin"], + proguard_specs = ["top.pro"], + deps = [":" + name + "/dep"], + ) + + analysis_test( + name = name, + impl = _test_java_plugin_exports_transitive_proguard_specs_impl, + target = name + "/top", + # Before Bazel 8, native rules use the native ProguardSpecProvider + attr_values = {"tags": ["min_bazel_8"]}, + provider_subject_factories = [struct( + type = ProguardSpecInfo, + name = "ProguardInfo", + factory = _new_proguard_info_subject, + )], + ) + +def _test_java_plugin_exports_transitive_proguard_specs_impl(env, target): + env.expect.that_target(target).provider(ProguardSpecInfo).specs().contains_exactly( + [ + "{package}/validated_proguard/{test_name}/top/{package}/top.pro_valid", + "{package}/validated_proguard/{test_name}/dep/{package}/dep.pro_valid", + ], + ) + +def _test_java_plugin_validates_proguard_specs(name): + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + proguard_specs = ["plugin.pro"], + ) + + analysis_test( + name = name, + impl = _test_java_plugin_validates_proguard_specs_impl, + target = name + "/plugin", + ) + +def _test_java_plugin_validates_proguard_specs_impl(env, target): + output_file = None + for f in target.output_groups["_hidden_top_level_INTERNAL_"].to_list(): + if f.basename == "plugin.pro_valid": + output_file = f + break + env.expect.that_target(target).action_generating( + output_file.short_path, + ).inputs().contains_at_least( + ["{package}/plugin.pro"], + ) + +def _test_java_plugin_validates_transitive_proguard_specs(name): + util.helper_target( + java_library, + name = name + "/transitive", + srcs = ["Transitive.java"], + proguard_specs = ["transitive.pro"], + ) + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + deps = [":" + name + "/transitive"], + ) + + analysis_test( + name = name, + impl = _test_java_plugin_validates_transitive_proguard_specs_impl, + targets = { + "transitive": name + "/transitive", + "plugin": name + "/plugin", + }, + ) + +def _test_java_plugin_validates_transitive_proguard_specs_impl(env, targets): + output_file = None + for f in targets.plugin.output_groups["_hidden_top_level_INTERNAL_"].to_list(): + if f.basename == "transitive.pro_valid": + output_file = f + break + + env.expect.that_target(targets.transitive).action_generating( + output_file.short_path, + ).inputs().contains_at_least(["{package}/transitive.pro"]) + +def _test_generates_api(name): + util.helper_target( + java_plugin, + name = name + "/api_generating", + srcs = ["ApiGeneratingPlugin.java"], + generates_api = True, + processor_class = "ApiGeneratingPlugin", + ) + + analysis_test( + name = name, + impl = _test_generates_api_impl, + target = name + "/api_generating", + ) + +def _test_generates_api_impl(env, target): + plugin_info = java_plugin_info_subject.from_target(env, target) + plugin_info.plugins().processor_classes().contains_exactly(["ApiGeneratingPlugin"]) + plugin_info.api_generating_plugins().processor_classes().contains_exactly(["ApiGeneratingPlugin"]) + plugin_info.plugins().processor_jars().contains_exactly([ + "{package}/lib{name}.jar", + ]) + plugin_info.api_generating_plugins().processor_jars().contains_exactly([ + "{package}/lib{name}.jar", + ]) + +def _test_generates_implementation(name): + util.helper_target( + java_plugin, + name = name + "/impl_generating", + srcs = ["ImplGeneratingPlugin.java"], + generates_api = False, + processor_class = "ImplGeneratingPlugin", + ) + + analysis_test( + name = name, + impl = _test_generates_implementation_impl, + target = name + "/impl_generating", + ) + +def _test_generates_implementation_impl(env, target): + plugin_info = java_plugin_info_subject.from_target(env, target) + plugin_info.plugins().processor_classes().contains_exactly(["ImplGeneratingPlugin"]) + plugin_info.api_generating_plugins().processor_classes().contains_exactly([]) + plugin_info.plugins().processor_jars().contains_exactly([ + "{package}/lib{test_name}/impl_generating.jar", + ]) + plugin_info.api_generating_plugins().processor_jars().contains_exactly([]) + +def _test_plugin_data_in_provider(name): + util.helper_target( + java_plugin, + name = name + "/impl_generating", + srcs = ["ImplGeneratingPlugin.java"], + data = ["data.txt"], + generates_api = False, + processor_class = "ImplGeneratingPlugin", + ) + + analysis_test( + name = name, + impl = _test_plugin_data_in_provider_impl, + target = name + "/impl_generating", + ) + +def _test_plugin_data_in_provider_impl(env, target): + plugin_info = java_plugin_info_subject.from_target(env, target) + plugin_info.plugins().processor_data().contains_exactly([ + "{package}/data.txt", + ]) + +def _test_plugin_data_in_action_inputs(name): + util.helper_target( + java_plugin, + name = name + "/impl_generating_lib", + srcs = ["ImplGeneratingPlugin.java"], + data = ["data.txt"], + generates_api = False, + processor_class = "ImplGeneratingPlugin", + ) + util.helper_target( + java_library, + name = name + "/lib", + plugins = [":" + name + "/impl_generating_lib"], + ) + + analysis_test( + name = name, + impl = _test_plugin_data_in_action_inputs_impl, + target = name + "/lib", + ) + +def _test_plugin_data_in_action_inputs_impl(env, target): + env.expect.that_target(target).action_generating("{package}/lib{name}.jar").inputs().contains_at_least([ + "{package}/data.txt", + ]) + def java_plugin_tests(name): test_suite( name = name, tests = [ _test_exposes_plugins_to_starlark, _test_exposes_api_generating_plugins_to_starlark, + _test_not_empty_processor_class, + _test_empty_processor_class, + _test_empty_processor_class_target, + _test_generates_api, + _test_plugin_data_in_provider, + _test_plugin_data_in_action_inputs, + _test_java_plugin_exports_transitive_proguard_specs, + _test_java_plugin_validates_proguard_specs, + _test_java_plugin_validates_transitive_proguard_specs, + _test_generates_implementation, ], ) From 7ba5fecb9e077f3854501089efdedf5b9bd90e06 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 24 Feb 2026 00:37:51 -0800 Subject: [PATCH 119/251] Internal change PiperOrigin-RevId: 874441487 Change-Id: Id054a171e3f5f2e8a477353c16bf2cc1ff8b8c3a --- .../common/rules/impl/bazel_java_import_impl.bzl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index 2a107a1e..c402fc44 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl @@ -63,11 +63,10 @@ def _process_with_ijars_if_needed(jars, ctx): return file_dict -def _check_export_error(ctx, exports): - not_in_allowlist = hasattr(ctx.attr, "_allowlist_java_import_exports") and not getattr(ctx.attr, "_allowlist_java_import_exports")[PackageSpecificationInfo].contains(ctx.label) +def _check_export_error(ctx, exports, permit_exports): disallow_java_import_exports = ctx.fragments.java.disallow_java_import_exports() - if len(exports) != 0 and (disallow_java_import_exports or not_in_allowlist): + if len(exports) != 0 and (disallow_java_import_exports or not permit_exports): fail("java_import.exports is no longer supported; use java_import.deps instead") def _check_empty_jars_error(ctx, jars): @@ -84,7 +83,9 @@ def bazel_java_import_rule( neverlink = False, proguard_specs = [], add_exports = [], - add_opens = []): + add_opens = [], + permit_exports = True, + skip_incomplete_deps_check = True): """Implements java_import. This rule allows the use of precompiled .jar files as libraries in other Java rules. @@ -100,6 +101,8 @@ def bazel_java_import_rule( proguard_specs: (list[File]) Files to be used as Proguard specification. add_exports: (list[str]) Allow this library to access the given /. add_opens: (list[str]) Allow this library to reflectively access the given /. + permit_exports: (bool) Allow using exports + skip_incomplete_deps_check: (bool) If this target is allowed to have incomplete deps Returns: (list[provider]) A list containing DefaultInfo, JavaInfo, @@ -107,15 +110,14 @@ def bazel_java_import_rule( """ _check_empty_jars_error(ctx, jars) - _check_export_error(ctx, exports) + _check_export_error(ctx, exports, permit_exports) collected_jars = _collect_jars(ctx, jars) all_deps = _filter_provider(JavaInfo, deps, exports) jdeps_artifact = None merged_java_info = java_common.merge(all_deps) - not_in_allowlist = hasattr(ctx.attr, "_allowlist_java_import_deps_checking") and not ctx.attr._allowlist_java_import_deps_checking[PackageSpecificationInfo].contains(ctx.label) - if not_in_allowlist and "incomplete-deps" not in ctx.attr.tags: + if not skip_incomplete_deps_check and "incomplete-deps" not in ctx.attr.tags: jdeps_artifact = import_deps_check( ctx, collected_jars, From c4133ab9a0735b85a98c7ffd5543437db6d7a725 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 24 Feb 2026 01:32:03 -0800 Subject: [PATCH 120/251] Get the last tag at `HEAD~1` for generating release notes Now that we're relying on a tag push for making releases, the latest tag at HEAD is the release we're currently making, and we want the previous tag. (in the earlier release process, we generated the release notes *before* creating the tag) (ignore-relnotes) PiperOrigin-RevId: 874468315 Change-Id: I1deb413ff6db4803f6c2eaf51da80c287ca78183 --- .bazelci/presubmit.yml | 1 + distro/relnotes.bzl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 704e6eb1..6ff8d263 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -95,6 +95,7 @@ tasks: - "git commit --allow-empty -m 'Fake init commit'" - "git tag -a 'fake-tag-for-testing' -m 'ignore'" - "git commit --allow-empty -m 'Fake commit message for testing'" + - "git tag -a 'fake-tag-for-testing2' -m 'ignore'" test_targets: - "//test:check_remote_jdk_configs_test" - "//test:check_remote_java_tools_configs_test" diff --git a/distro/relnotes.bzl b/distro/relnotes.bzl index 9d76230a..9c0806af 100644 --- a/distro/relnotes.bzl +++ b/distro/relnotes.bzl @@ -5,7 +5,7 @@ def print_rel_notes(*, name, version, archive): name = name, outs = [name + ".txt"], cmd = """ - last_rel=$$(git describe --tags --abbrev=0) + last_rel=$$(git describe --tags --abbrev=0 HEAD~1) changelog=$$(/usr/bin/git log tags/$$last_rel..HEAD --format=oneline --invert-grep --grep 'ignore-relnotes' --) sha=$$(/usr/bin/sha256sum $(SRCS) | cut -d ' ' -f1) cat > $@ < Date: Tue, 24 Feb 2026 04:33:49 -0800 Subject: [PATCH 121/251] Fix build with Bazel@HEAD Broken by https://github.com/bazelbuild/bazel/pull/27674 (ignore-relnotes) PiperOrigin-RevId: 874542646 Change-Id: I4f1e8c9baae8330d703d6f7eb145e5a3ee2923fc --- java/BUILD | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/BUILD b/java/BUILD index b613191c..bcb113a7 100644 --- a/java/BUILD +++ b/java/BUILD @@ -61,6 +61,11 @@ bzl_library( visibility = ["//visibility:public"], ) +exports_files( + ["java_single_jar.bzl"], + visibility = ["//test:__pkg__"], +) + bzl_library( name = "java_single_jar", srcs = ["java_single_jar.bzl"], From 28e7687fc6896e81439d8db71f234d43dcf2bc9f Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 24 Feb 2026 04:57:00 -0800 Subject: [PATCH 122/251] Work around the shallow checkout behavior of `release_ruleset.yaml`[^1] We need the full history of commits and tags to generate release notes. [^1]: While https://github.com/actions/checkout/blob/main/action.yml supports deep checkouts, we can't pass parameters to it unless https://github.com/bazel-contrib/.github/blob/master/.github/workflows/release_ruleset.yaml exposes a parameter for it. (ignore-relnotes) PiperOrigin-RevId: 874550299 Change-Id: I498f09063adaebb0d0709f1cebdfc9b0067215ae --- distro/relnotes.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/distro/relnotes.bzl b/distro/relnotes.bzl index 9c0806af..e47c3c95 100644 --- a/distro/relnotes.bzl +++ b/distro/relnotes.bzl @@ -5,6 +5,7 @@ def print_rel_notes(*, name, version, archive): name = name, outs = [name + ".txt"], cmd = """ + [ "$$(/usr/bin/git rev-parse --is-shallow-repository)" == "true" ] && /usr/bin/git fetch --unshallow last_rel=$$(git describe --tags --abbrev=0 HEAD~1) changelog=$$(/usr/bin/git log tags/$$last_rel..HEAD --format=oneline --invert-grep --grep 'ignore-relnotes' --) sha=$$(/usr/bin/sha256sum $(SRCS) | cut -d ' ' -f1) From 3a85c8f5c1da1acbcef426af4e2d6536310a36fa Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 26 Feb 2026 13:59:32 -0800 Subject: [PATCH 123/251] Migrate *_getCommandLineFromToolchain Java tests to Starlark PiperOrigin-RevId: 875878855 Change-Id: Idf86d2f3c0529fd1749035b2f22d3c5447fdf632 --- test/java/testutil/javac_action_subject.bzl | 1 + test/java/toolchains/java_toolchain_tests.bzl | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index ef23812c..5dfbab4a 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -24,6 +24,7 @@ def _new_javac_action_subject(env, target, output): target = lambda: _create_subject_for_flag("-target", self.parsed_flags, self.meta), xmaxerrs = lambda: _create_subject_for_flag("-Xmaxerrs", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), + executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, argv = action_subject.argv, ) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 976bb082..a13e0868 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -2,6 +2,7 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") @@ -110,11 +111,59 @@ def _test_jacocorunner_impl(env, target): assert_toolchain.jacocorunner().short_path_equals("{package}/myjacocorunner.jar") +def _test_singlejar_get_command_line(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_binary, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_singlejar_get_command_line_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + # This crashes in earlier Bazel versions where native rules handled deploy jars differently. + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_singlejar_get_command_line_impl(env, target): + assert_javac_action = javac_action_subject.of(env, target, "{package}/{name}_deploy.jar") + assert_javac_action.executable_file_name().equals(target.label.package + "/singlejar") + +def _test_genclass_get_command_line(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + javacopts = ["-processor NOSUCH"], + ) + + analysis_test( + name = name, + impl = _test_genclass_get_command_line_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_genclass_get_command_line_impl(env, target): + assert_javac_action = javac_action_subject.of(env, target, "{package}/lib{name}-gen.jar") + + assert_javac_action.jar().contains_exactly(["{package}/GenClass_deploy.jar"]) + def java_toolchain_tests(name): test_suite( name = name, tests = [ _test_jacocorunner, _test_javac_gets_options, + _test_singlejar_get_command_line, + _test_genclass_get_command_line, ], ) From 69e858e86a6981f3744efd9f594f9d7b48eda775 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 26 Feb 2026 14:01:04 -0800 Subject: [PATCH 124/251] Migrate JavaToolchain timezone data tests to Starlark. PiperOrigin-RevId: 875879430 Change-Id: Iae180a7ebfb2dd4e3dc42eb23fbcb229c7bb443f --- .../testutil/java_toolchain_info_subject.bzl | 1 + test/java/testutil/javac_action_subject.bzl | 1 + test/java/toolchains/java_toolchain_tests.bzl | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/test/java/testutil/java_toolchain_info_subject.bzl b/test/java/testutil/java_toolchain_info_subject.bzl index af6934b1..e52302ab 100644 --- a/test/java/testutil/java_toolchain_info_subject.bzl +++ b/test/java/testutil/java_toolchain_info_subject.bzl @@ -6,6 +6,7 @@ load("//java/common:java_common.bzl", "java_common") def _new_java_toolchain_info_subject(info, meta): public = struct( jacocorunner = lambda: subjects.file(info.jacocorunner.executable, meta.derive("jacocorunner.executable")), + timezone_data = lambda: subjects.file(info._timezone_data, meta.derive("_timezone_data")), ) return public diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 5dfbab4a..28d19165 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -24,6 +24,7 @@ def _new_javac_action_subject(env, target, output): target = lambda: _create_subject_for_flag("-target", self.parsed_flags, self.meta), xmaxerrs = lambda: _create_subject_for_flag("-Xmaxerrs", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), + sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, argv = action_subject.argv, diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index a13e0868..93776476 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -1,6 +1,7 @@ """Tests for the java_toolchain rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") @@ -157,6 +158,42 @@ def _test_genclass_get_command_line_impl(env, target): assert_javac_action.jar().contains_exactly(["{package}/GenClass_deploy.jar"]) +def _test_timezone_data_is_correct(name): + _declare_java_toolchain(name = name) + + analysis_test( + name = name, + impl = _test_timezone_data_is_correct_impl, + target = name + "/java_toolchain", + ) + +def _test_timezone_data_is_correct_impl(env, target): + java_toolchain_info_subject.from_target(env, target).timezone_data().short_path_equals( + "{package}/tzdata.jar", + ) + +def _test_java_binary_uses_timezone_data(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_binary, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_uses_timezone_data_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_java_binary_uses_timezone_data_impl(env, target): + assert_action = javac_action_subject.of(env, target, "{package}/{name}.jar") + assert_action.sources().contains("{package}/tzdata.jar") + assert_action.inputs().contains_predicate(matching.file_basename_equals("tzdata.jar")) + def java_toolchain_tests(name): test_suite( name = name, @@ -165,5 +202,7 @@ def java_toolchain_tests(name): _test_javac_gets_options, _test_singlejar_get_command_line, _test_genclass_get_command_line, + _test_timezone_data_is_correct, + _test_java_binary_uses_timezone_data, ], ) From f4481046b84c90596fe21a178ca9123615b3cf4c Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 26 Feb 2026 14:14:24 -0800 Subject: [PATCH 125/251] Migrate ijar unit test to starlark PiperOrigin-RevId: 875885779 Change-Id: Ic86ea8607c6ffd13ebfe3c31c60d31579c2ae099 --- test/java/toolchains/java_toolchain_tests.bzl | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 93776476..7bcbb38a 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -8,6 +8,7 @@ load("//java:java_library.bzl", "java_library") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//java/toolchains:java_toolchain.bzl", "java_toolchain") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:java_toolchain_info_subject.bzl", "java_toolchain_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") @@ -194,6 +195,30 @@ def _test_java_binary_uses_timezone_data_impl(env, target): assert_action.sources().contains("{package}/tzdata.jar") assert_action.inputs().contains_predicate(matching.file_basename_equals("tzdata.jar")) +def _test_ijar_get_command_line(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_ijar_get_command_line_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:java_header_compilation": "false", + }, + ) + +def _test_ijar_get_command_line_impl(env, target): + compile_jar = java_info_subject.from_target(env, target).java_outputs().singleton().compile_jar().actual + env.expect.that_target(target).action_generating(compile_jar.short_path).argv().contains( + "{package}/ijar", + ) + def java_toolchain_tests(name): test_suite( name = name, @@ -204,5 +229,6 @@ def java_toolchain_tests(name): _test_genclass_get_command_line, _test_timezone_data_is_correct, _test_java_binary_uses_timezone_data, + _test_ijar_get_command_line, ], ) From 3789f0580fe0a19213ca30683bcf7db9eb419ca5 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 27 Feb 2026 05:02:34 -0800 Subject: [PATCH 126/251] Add a test for `java_binary`'s use of the transitive validation output group Regression test for https://github.com/bazelbuild/rules_java/issues/342 Fixes https://github.com/bazelbuild/rules_java/issues/342 PiperOrigin-RevId: 876195296 Change-Id: Iee5f646fde01dc9c604f3d62187a99f92ba1cadf --- test/java/common/rules/java_binary_tests.bzl | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 9ddadbd9..10728fb3 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -1,5 +1,6 @@ """Tests for the java_binary rule""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") @@ -7,6 +8,7 @@ load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") +load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") load("//test/java/testutil:rules/forward_java_info.bzl", "java_info_forwarding_rule") @@ -194,6 +196,59 @@ def _test_java_compile_only_impl(env, target): "compilation_outputs", ).contains_exactly(["{package}/{name}.jar"]) +def _test_java_binary_can_set_transitive_validation(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + env_name = name + "_env" + util.helper_target( + java_library, + name = env_name + "_leaf", + srcs = ["A.java"], + neverlink = True, # add runtime_classpath to validation output group + ) + util.helper_target( + java_binary, + name = env_name, + srcs = ["Env.java"], + deps = [env_name + "_leaf"], + neverlink = True, # add runtime_classpath to validation output group + ) + util.helper_target( + java_binary, + name = name + "_bin", + srcs = ["Bin.java"], + data = [env_name], + deploy_env = [env_name], + create_executable = False, + ) + + analysis_test( + name = name, + impl = _test_java_binary_can_set_transitive_validation_impl, + targets = { + "bin": name + "_bin", + "env": env_name, + }, + # Turn off other validations + config_settings = { + "//command_line_option:experimental_run_android_lint_on_java_rules": False, + "//command_line_option:experimental_one_version_enforcement": "OFF", + }, + ) + +def _test_java_binary_can_set_transitive_validation_impl(env, targets): + # ensure the env target has validation outputs + env.expect.that_target(targets.env).output_group("_validation").contains_at_least([ + "{package}/{name}.jar", + "{package}/lib{name}_leaf.jar", + ]) + + # ensure they don't propagate to `bin` because they're a part of the `deploy_env` + env.expect.that_target(targets.bin).output_group("_validation").contains_exactly([]) + def java_binary_tests(name): test_suite( name = name, @@ -203,5 +258,6 @@ def java_binary_tests(name): _test_java_binary_attributes, _test_java_binary_propagates_direct_native_libraries, _test_java_compile_only, + _test_java_binary_can_set_transitive_validation, ], ) From ec317b1f24d41c169f4d4586c695f8079972c6d7 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 2 Mar 2026 02:55:48 -0800 Subject: [PATCH 127/251] Remove `java_common.add_constraints` PiperOrigin-RevId: 877302145 Change-Id: Ib389d091ec6dea4ef1cf89ed1de1b359aa46da1c --- java/private/java_common.bzl | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 6d877d76..174f4e6a 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl @@ -29,7 +29,6 @@ load( ":java_info.bzl", "JavaInfo", "JavaPluginInfo", - _java_info_add_constraints = "add_constraints", _java_info_make_non_strict = "make_non_strict", _java_info_merge = "merge", _java_info_set_annotation_processing = "set_annotation_processing", @@ -215,21 +214,6 @@ def _make_non_strict(java_info): def _get_message_bundle_info(): return None if semantics.IS_BAZEL else MessageBundleInfo -def _add_constraints(java_info, constraints = []): - """Returns a copy of the given JavaInfo with the given constraints added. - - Args: - java_info: (JavaInfo) The JavaInfo to enhance - constraints: ([str]) Constraints to add - - Returns: - (JavaInfo) - """ - if semantics.IS_BAZEL: - return java_info - - return _java_info_add_constraints(java_info, constraints = constraints) - def _get_constraints(java_info): """Returns a set of constraints added. @@ -308,7 +292,6 @@ def _make_java_common(): if get_internal_java_common().google_legacy_api_enabled(): methods.update( MessageBundleInfo = _get_message_bundle_info(), # struct field that is None in bazel - add_constraints = _add_constraints, get_constraints = _get_constraints, set_annotation_processing = _set_annotation_processing, java_toolchain_label = _java_toolchain_label, From 26c3467b1861a9b8d73464e5c531c1b3d015b5b1 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 2 Mar 2026 07:08:39 -0800 Subject: [PATCH 128/251] Migrate JavaToolchain header compilation tests to Starlark. PiperOrigin-RevId: 877382139 Change-Id: Ia255bf27ee9041670ac074c8466c8d5dc4336034 --- test/java/toolchains/java_toolchain_tests.bzl | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 7bcbb38a..07a3ce5c 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -219,6 +219,89 @@ def _test_ijar_get_command_line_impl(env, target): "{package}/ijar", ) +def _test_no_header_compiler_header_compilation_enabled_fails(name): + _declare_java_toolchain( + name = name, + header_compiler = None, + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_no_header_compiler_header_compilation_enabled_fails_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:java_header_compilation": "true", + }, + expect_failure = True, + ) + +def _test_no_header_compiler_header_compilation_enabled_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("header compilation was requested but it is not supported by the " + + "current Java toolchain"), + ) + +def _test_no_header_compiler_direct_header_compilation_enabled_fails(name): + _declare_java_toolchain( + name = name, + header_compiler_direct = None, + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_no_header_compiler_direct_header_compilation_enabled_fails_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:java_header_compilation": "true", + }, + expect_failure = True, + ) + +def _test_no_header_compiler_direct_header_compilation_enabled_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("header compilation was requested but it is not supported by the " + + "current Java toolchain"), + ) + +def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(name): + _declare_java_toolchain( + name = name, + header_compiler = None, + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl, + target = name + "/a", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:java_header_compilation": "false", + }, + ) + +def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl( + env, # @unused + target): # @unused + # Implicitly succeeds. + pass + def java_toolchain_tests(name): test_suite( name = name, @@ -230,5 +313,8 @@ def java_toolchain_tests(name): _test_timezone_data_is_correct, _test_java_binary_uses_timezone_data, _test_ijar_get_command_line, + _test_no_header_compiler_header_compilation_enabled_fails, + _test_no_header_compiler_direct_header_compilation_enabled_fails, + _test_no_header_compiler_header_compilation_disabled_analyzes_successfully, ], ) From 07ba1c0d36508926099ec1e3e1f44ea1f602b4da Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 2 Mar 2026 07:17:21 -0800 Subject: [PATCH 129/251] Migrate JavaToolchainProvider tests to Starlark. PiperOrigin-RevId: 877385412 Change-Id: I1095c37592ce0ee1d4847cec8893219df5ff5a9c --- .../testutil/java_toolchain_info_subject.bzl | 2 ++ test/java/toolchains/java_toolchain_tests.bzl | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/test/java/testutil/java_toolchain_info_subject.bzl b/test/java/testutil/java_toolchain_info_subject.bzl index e52302ab..a3304f42 100644 --- a/test/java/testutil/java_toolchain_info_subject.bzl +++ b/test/java/testutil/java_toolchain_info_subject.bzl @@ -7,6 +7,8 @@ def _new_java_toolchain_info_subject(info, meta): public = struct( jacocorunner = lambda: subjects.file(info.jacocorunner.executable, meta.derive("jacocorunner.executable")), timezone_data = lambda: subjects.file(info._timezone_data, meta.derive("_timezone_data")), + header_compiler_builtin_processors = lambda: subjects.collection(info._header_compiler_builtin_processors.to_list(), meta.derive("_header_compiler_builtin_processors")), + reduced_classpath_incompatible_processors = lambda: subjects.collection(info._reduced_classpath_incompatible_processors.to_list(), meta.derive("_reduced_classpath_incompatible_processors")), ) return public diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 07a3ce5c..1beca093 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -302,6 +302,40 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_i # Implicitly succeeds. pass +def _test_header_compiler_builtin_processors(name): + util.helper_target( + java_toolchain, + name = name + "/java_toolchain", + header_compiler_builtin_processors = ["BuiltinProc1", "BuiltinProc2"], + singlejar = "singlejar", + ) + + analysis_test( + name = name, + impl = _test_header_compiler_builtin_processors_impl, + target = name + "/java_toolchain", + ) + +def _test_header_compiler_builtin_processors_impl(env, target): + java_toolchain_info_subject.from_target(env, target).header_compiler_builtin_processors().contains_exactly(["BuiltinProc1", "BuiltinProc2"]) + +def _test_reduced_classpath_incompatible_processors(name): + util.helper_target( + java_toolchain, + name = name + "/java_toolchain", + reduced_classpath_incompatible_processors = ["IncompatibleProc1", "IncompatibleProc2"], + singlejar = "singlejar", + ) + + analysis_test( + name = name, + impl = _test_reduced_classpath_incompatible_processors_impl, + target = name + "/java_toolchain", + ) + +def _test_reduced_classpath_incompatible_processors_impl(env, target): + java_toolchain_info_subject.from_target(env, target).reduced_classpath_incompatible_processors().contains_exactly(["IncompatibleProc1", "IncompatibleProc2"]) + def java_toolchain_tests(name): test_suite( name = name, @@ -316,5 +350,7 @@ def java_toolchain_tests(name): _test_no_header_compiler_header_compilation_enabled_fails, _test_no_header_compiler_direct_header_compilation_enabled_fails, _test_no_header_compiler_header_compilation_disabled_analyzes_successfully, + _test_header_compiler_builtin_processors, + _test_reduced_classpath_incompatible_processors, ], ) From e7b4e1d1c956ea550f51840537d682cc10149853 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 2 Mar 2026 07:36:06 -0800 Subject: [PATCH 130/251] Move javaToolchain_* tests to starlark. PiperOrigin-RevId: 877391792 Change-Id: I4a260a12861387cf5cbc5f229fcd7294c1d4c824 --- test/java/toolchains/java_toolchain_tests.bzl | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 1beca093..3019a667 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -336,6 +336,85 @@ def _test_reduced_classpath_incompatible_processors(name): def _test_reduced_classpath_incompatible_processors_impl(env, target): java_toolchain_info_subject.from_target(env, target).reduced_classpath_incompatible_processors().contains_exactly(["IncompatibleProc1", "IncompatibleProc2"]) +def _test_location_expansion_in_jvm_opts(name): + _declare_java_toolchain( + name = name, + tools = [name + "/jsr305.jar", name + "/javac"], + jvm_opts = [ + "--patch-module=jdk.compiler=$(location " + name + "/javac)", + "--patch-module=java.xml.ws.annotation=$(location " + name + "/jsr305.jar)", + ], + javabuilder_jvm_opts = ["-Xshare:auto"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["a.java"], + ) + + analysis_test( + name = name, + impl = _test_location_expansion_in_jvm_opts_impl, + target = name + "/lib", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_location_expansion_in_jvm_opts_impl(env, target): + assert_javac_action = env.expect.that_target(target).action_generating("{package}/lib{name}.jar") + assert_javac_action.argv().contains("--patch-module=jdk.compiler={package}/{test_name}/javac") + assert_javac_action.argv().contains("--patch-module=java.xml.ws.annotation={package}/{test_name}/jsr305.jar") + assert_javac_action.argv().contains("-Xshare:auto") + assert_javac_action.inputs().contains("{package}/{test_name}/jsr305.jar") + +def _test_location_expansion_with_multiple_artifacts_fails(name): + util.helper_target( + native.filegroup, + name = name + "/fg", + srcs = ["one", "two"], + ) + _declare_java_toolchain( + name = name, + tools = [name + "/fg"], + javabuilder_jvm_opts = ["$(location " + name + "/fg)"], + ) + + analysis_test( + name = name, + impl = _test_location_expansion_with_multiple_artifacts_fails_impl, + target = name + "/java_toolchain", + expect_failure = True, + ) + +def _test_location_expansion_with_multiple_artifacts_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("$(location) expression expands to more than one file"), + ) + +def _test_timezone_data_with_multiple_artifacts_fails(name): + util.helper_target( + native.filegroup, + name = name + "/fg", + srcs = ["one", "two"], + ) + _declare_java_toolchain( + name = name, + timezone_data = name + "/fg", + ) + + analysis_test( + name = name, + impl = _test_timezone_data_with_multiple_artifacts_fails_impl, + target = name + "/java_toolchain", + expect_failure = True, + ) + +def _test_timezone_data_with_multiple_artifacts_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("must produce a single file"), + ) + def java_toolchain_tests(name): test_suite( name = name, @@ -352,5 +431,8 @@ def java_toolchain_tests(name): _test_no_header_compiler_header_compilation_disabled_analyzes_successfully, _test_header_compiler_builtin_processors, _test_reduced_classpath_incompatible_processors, + _test_location_expansion_in_jvm_opts, + _test_location_expansion_with_multiple_artifacts_fails, + _test_timezone_data_with_multiple_artifacts_fails, ], ) From 617f16791f16889ca73db9a526ec83022c03385d Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 3 Mar 2026 07:17:21 -0800 Subject: [PATCH 131/251] Migrate JavaToolchainTest cases to Starlark analysis tests. PiperOrigin-RevId: 877933571 Change-Id: I271712beef84d4d0b1e5b1b2646f5d375b5ae7b7 --- MODULE.bazel | 6 +- test/java/testutil/javac_action_subject.bzl | 11 +- .../testutil/javac_action_subject_tests.bzl | 20 ++- test/java/toolchains/java_toolchain_tests.bzl | 129 +++++++++++++++++- 4 files changed, 145 insertions(+), 21 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index de8fe111..204b8e88 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -131,9 +131,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-TqwTCQnzt/hRKQtdJ7d8ebtZ8+I8IMgmWiEjOKvo6mI=", - strip_prefix = "rules_testing-f8e869d452507fa4a59748c9d69cfab63ec9385a", - urls = ["https://github.com/bazelbuild/rules_testing/archive/f8e869d452507fa4a59748c9d69cfab63ec9385a.tar.gz"], + integrity = "sha256-d/94Ix5IoGXk9rP1HjYKxPMH8ccwX5b1Qxs8BKg4WRg=", + strip_prefix = "rules_testing-ac97ba507116056cd489161b5e99dd8014685adc", + urls = ["https://github.com/bazelbuild/rules_testing/archive/ac97ba507116056cd489161b5e99dd8014685adc.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 28d19165..ed6e9fa2 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -20,9 +20,7 @@ def _new_javac_action_subject(env, target, output): public = struct( direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), - source = lambda: _create_subject_for_flag("-source", self.parsed_flags, self.meta), - target = lambda: _create_subject_for_flag("-target", self.parsed_flags, self.meta), - xmaxerrs = lambda: _create_subject_for_flag("-Xmaxerrs", self.parsed_flags, self.meta), + javacopts = lambda: _create_subject_for_flag("--javacopts", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), @@ -37,7 +35,12 @@ def _parse_flags(argv): for idx, arg in enumerate(argv): if idx == 0: continue # java command - if arg.startswith("-"): + + if current_flag_name == "--javacopts" and arg == "--": + current_flag_name = None + continue + + if arg.startswith("-") and current_flag_name != "--javacopts": if "=" in arg: parts = arg.split("=", 1) flag_values.setdefault(parts[0], []).append(parts[1]) diff --git a/test/java/testutil/javac_action_subject_tests.bzl b/test/java/testutil/javac_action_subject_tests.bzl index eba3f76b..c1e577be 100644 --- a/test/java/testutil/javac_action_subject_tests.bzl +++ b/test/java/testutil/javac_action_subject_tests.bzl @@ -18,6 +18,7 @@ def _parse_flags_test_impl(ctx): "JavaBuilder_deploy.jar", "--output", "blaze-out/k8/bin/pkg/libfoo.jar", + "--javacopts", "-source", "21", "-target", @@ -49,13 +50,18 @@ def _parse_flags_test_impl(ctx): ], "-jar": ["JavaBuilder_deploy.jar"], "--output": ["blaze-out/k8/bin/pkg/libfoo.jar"], - "-source": ["21"], - "-target": ["17"], - "-g": [], - "-parameters": [], - "-sourcepath": [":"], - "-Xmaxerrs": ["123"], - "--": [], + "--javacopts": [ + "-source", + "21", + "-target", + "17", + "-g", + "-parameters", + "-sourcepath", + ":", + "-Xmaxerrs", + "123", + ], "--strict_java_deps": ["ERROR"], "--classpath": ["pkg/bar-hjar.jar", "other/pkg/baz.jar"], }, flags) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 3019a667..f685fddd 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -1,10 +1,11 @@ """Tests for the java_toolchain rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") -load("@rules_testing//lib:truth.bzl", "matching") +load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") +load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//java/toolchains:java_toolchain.bzl", "java_toolchain") @@ -83,15 +84,19 @@ def _test_javac_gets_options(name): def _test_javac_gets_options_impl(env, targets): assert_javac_action = javac_action_subject.of(env, targets.a, "{package}/lib{name}.jar") - assert_javac_action.source().contains_exactly(["6"]) - assert_javac_action.target().contains_exactly(["6"]) - assert_javac_action.xmaxerrs().contains_exactly(["500"]) + assert_javac_action.javacopts().contains_at_least([ + "-source", + "6", + "-target", + "6", + "-Xlint:toto", + "-Xmaxerrs", + "500", + ]) assert_javac_action.jar().contains_exactly(["{package}/JavaBuilder_deploy.jar"]) assert_javac_action.inputs().contains("{package}/rt.jar") - assert_argv = assert_javac_action.argv() - assert_argv.contains("-Xlint:toto") - assert_argv.not_contains("-g") + assert_javac_action.javacopts().not_contains("-g") assert_header_action = javac_action_subject.of(env, targets.b, "{package}/lib{name}-hjar.jar") assert_header_action.argv().contains("{package}/turbine_direct") @@ -415,6 +420,113 @@ def _test_timezone_data_with_multiple_artifacts_fails_impl(env, target): matching.contains("must produce a single file"), ) +def _test_java_compile_action_target_gets_javacopts_from_toolchain(name): + _declare_java_toolchain( + name = name, + javacopts = ["-XDtoolchainJavacFlag"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["a.java"], + ) + analysis_test( + name = name, + impl = _test_java_compile_action_target_gets_javacopts_from_toolchain_impl, + target = name + "/lib", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:javacopt": ["-XDcommandLineJavacFlag"], + "//command_line_option:host_javacopt": ["-XDhostCommandLineJavacFlag"], + }, + ) + +def _test_java_compile_action_target_gets_javacopts_from_toolchain_impl(env, target): + assert_javacopts = javac_action_subject.of(env, target, "{package}/lib{name}.jar").javacopts() + assert_javacopts.contains_exactly([ + "-source", + "6", + "-target", + "6", + "-Xlint:toto", + "-XDtoolchainJavacFlag", + "-XDcommandLineJavacFlag", + ]) + +def _test_java_compile_action_exec_gets_javacopts_from_toolchain(name): + _declare_java_toolchain( + name = name, + javacopts = ["-XDtoolchainJavacFlag"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["a.java"], + ) + util.helper_target( + util.force_exec_config, + name = name + "/exec_lib", + tools = [name + "/lib"], + ) + analysis_test( + name = name, + impl = _test_java_compile_action_exec_gets_javacopts_from_toolchain_impl, + target = name + "/exec_lib", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + "//command_line_option:javacopt": ["-XDcommandLineJavacFlag"], + "//command_line_option:host_javacopt": ["-XDhostCommandLineJavacFlag"], + }, + ) + +def _test_java_compile_action_exec_gets_javacopts_from_toolchain_impl(env, target): + lib = env.expect.that_target(target).attr("tools", factory = subjects.collection).actual[0] + assert_javacopts = javac_action_subject.of(env, lib, "{package}/lib{name}.jar").javacopts() + assert_javacopts.contains_exactly([ + "-source", + "6", + "-target", + "6", + "-Xlint:toto", + "-XDtoolchainJavacFlag", + "-XDhostCommandLineJavacFlag", + ]) + +def _test_java_compile_action_uses_tool_specific_jvm_opts(name): + _declare_java_toolchain( + name = name, + jvm_opts = ["-Xbase"], + javabuilder_jvm_opts = ["-DjavabuilderFlag=1"], + turbine_jvm_opts = ["-DturbineFlag=1"], + ) + util.helper_target( + java_plugin, + name = name + "/plugin", + processor_class = "Proc", + generates_api = True, + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["a.java"], + plugins = [name + "/plugin"], + ) + analysis_test( + name = name, + impl = _test_java_compile_action_uses_tool_specific_jvm_opts_impl, + target = name + "/lib", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_java_compile_action_uses_tool_specific_jvm_opts_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.argv().contains("-DjavabuilderFlag=1") + + header_action = env.expect.that_target(target).action_generating("{package}/lib{name}-hjar.jar") + header_action.argv().contains("-DturbineFlag=1") + def java_toolchain_tests(name): test_suite( name = name, @@ -434,5 +546,8 @@ def java_toolchain_tests(name): _test_location_expansion_in_jvm_opts, _test_location_expansion_with_multiple_artifacts_fails, _test_timezone_data_with_multiple_artifacts_fails, + _test_java_compile_action_target_gets_javacopts_from_toolchain, + _test_java_compile_action_exec_gets_javacopts_from_toolchain, + _test_java_compile_action_uses_tool_specific_jvm_opts, ], ) From 85d5bf8293301a58933de3e1119ad99604b5873b Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 3 Mar 2026 07:38:27 -0800 Subject: [PATCH 132/251] Move JavaToolchain location expansion test to Starlark. PiperOrigin-RevId: 877941010 Change-Id: I0709e76b1eeea9d572256b921ab27c98019e49eb --- .../testutil/java_toolchain_info_subject.bzl | 14 +++++++ test/java/toolchains/java_toolchain_tests.bzl | 40 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/test/java/testutil/java_toolchain_info_subject.bzl b/test/java/testutil/java_toolchain_info_subject.bzl index a3304f42..2757bfce 100644 --- a/test/java/testutil/java_toolchain_info_subject.bzl +++ b/test/java/testutil/java_toolchain_info_subject.bzl @@ -3,12 +3,26 @@ load("@rules_testing//lib:truth.bzl", "subjects") load("//java/common:java_common.bzl", "java_common") +def _new_java_builder_subject(tool_info, meta): + return subjects.struct( + struct( + data = [f.path for f in tool_info.data.to_list()], + jvm_opts = tool_info.jvm_opts.to_list(), + ), + meta = meta, + attrs = { + "data": lambda values, *, meta: subjects.collection(values, meta = meta, format = True), + "jvm_opts": lambda values, *, meta: subjects.collection(values, meta = meta, format = True), + }, + ) + def _new_java_toolchain_info_subject(info, meta): public = struct( jacocorunner = lambda: subjects.file(info.jacocorunner.executable, meta.derive("jacocorunner.executable")), timezone_data = lambda: subjects.file(info._timezone_data, meta.derive("_timezone_data")), header_compiler_builtin_processors = lambda: subjects.collection(info._header_compiler_builtin_processors.to_list(), meta.derive("_header_compiler_builtin_processors")), reduced_classpath_incompatible_processors = lambda: subjects.collection(info._reduced_classpath_incompatible_processors.to_list(), meta.derive("_reduced_classpath_incompatible_processors")), + javabuilder = lambda: _new_java_builder_subject(info._javabuilder, meta.derive("_javabuilder")), ) return public diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index f685fddd..9ca28577 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -527,6 +527,45 @@ def _test_java_compile_action_uses_tool_specific_jvm_opts_impl(env, target): header_action = env.expect.that_target(target).action_generating("{package}/lib{name}-hjar.jar") header_action.argv().contains("-DturbineFlag=1") +def _test_javabuilder_location_expansion_with_multiple_artifacts(name): + util.helper_target( + native.filegroup, + name = name + "/fg1", + srcs = ["a", "b"], + ) + util.helper_target( + native.filegroup, + name = name + "/fg2", + srcs = ["c", "d"], + ) + _declare_java_toolchain( + name = name, + javabuilder_data = [name + "/fg1", name + "/fg2"], + javabuilder_jvm_opts = [ + "$(locations " + name + "/fg1)", + "$(locations " + name + "/fg2)", + ], + ) + + analysis_test( + name = name, + impl = _test_javabuilder_location_expansion_with_multiple_artifacts_impl, + target = name + "/java_toolchain", + ) + +def _test_javabuilder_location_expansion_with_multiple_artifacts_impl(env, target): + assert_javabuilder = java_toolchain_info_subject.from_target(env, target).javabuilder() + assert_javabuilder.data().contains_exactly([ + "{package}/a", + "{package}/b", + "{package}/c", + "{package}/d", + ]).in_order() + assert_javabuilder.jvm_opts().contains_exactly([ + "{package}/a {package}/b", + "{package}/c {package}/d", + ]).in_order() + def java_toolchain_tests(name): test_suite( name = name, @@ -549,5 +588,6 @@ def java_toolchain_tests(name): _test_java_compile_action_target_gets_javacopts_from_toolchain, _test_java_compile_action_exec_gets_javacopts_from_toolchain, _test_java_compile_action_uses_tool_specific_jvm_opts, + _test_javabuilder_location_expansion_with_multiple_artifacts, ], ) From f64dab7c5a4e424ff86d33ef83973618966b84bc Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 3 Mar 2026 10:17:29 -0800 Subject: [PATCH 133/251] Add a test for deploy jars with custom singlejar PiperOrigin-RevId: 878010346 Change-Id: I44216adca0c605f3bcadb5030f3524f144ca7d23 --- test/java/common/rules/BUILD | 3 + .../rules/deploy_archive_builder_tests.bzl | 92 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 test/java/common/rules/deploy_archive_builder_tests.bzl diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 2311a3f2..cc2cd337 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -1,3 +1,4 @@ +load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") @@ -7,6 +8,8 @@ load(":merge_attrs_tests.bzl", "merge_attrs_test_suite") package(default_applicable_licenses = ["@rules_java//:license"]) +deploy_archive_builder_test_suite(name = "deploy_archive_builder_tests") + merge_attrs_test_suite(name = "merge_attrs_tests") java_binary_tests(name = "java_binary_tests") diff --git a/test/java/common/rules/deploy_archive_builder_tests.bzl b/test/java/common/rules/deploy_archive_builder_tests.bzl new file mode 100644 index 00000000..32e75e91 --- /dev/null +++ b/test/java/common/rules/deploy_archive_builder_tests.bzl @@ -0,0 +1,92 @@ +"""Tests for DeployArchiveBuilder.""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") +load("//java/common:java_semantics.bzl", "semantics") +load("//java/toolchains:java_runtime.bzl", "java_runtime") +load("//java/toolchains:java_toolchain.bzl", "java_toolchain") + +def _declare_java_toolchain(*, name, **kwargs): + java_runtime_name = name + "/runtime" + util.helper_target( + java_runtime, + name = java_runtime_name, + ) + toolchain_attrs = { + "source_version": "6", + "target_version": "6", + "bootclasspath": ["rt.jar"], + "xlint": ["toto"], + "javacopts": ["-Xmaxerrs 500"], + "compatible_javacopts": { + "android": ["-XDandroidCompatible"], + "testonly": ["-XDtestOnly"], + "public_visibility": ["-XDpublicVisibility"], + }, + "tools": [":javac_canary.jar"], + "javabuilder": ":JavaBuilder_deploy.jar", + "header_compiler": ":turbine_canary_deploy.jar", + "header_compiler_direct": ":turbine_direct", + "singlejar": "singlejar", + "ijar": "ijar", + "genclass": "GenClass_deploy.jar", + "timezone_data": "tzdata.jar", + "header_compiler_builtin_processors": ["BuiltinProc1", "BuiltinProc2"], + "reduced_classpath_incompatible_processors": [ + "IncompatibleProc1", + "IncompatibleProc2", + ], + "java_runtime": java_runtime_name, + } + toolchain_attrs.update(kwargs) + util.helper_target( + java_toolchain, + name = name + "/java_toolchain", + **toolchain_attrs + ) + util.helper_target( + native.toolchain, + name = name + "/toolchain", + toolchain = name + "/java_toolchain", + toolchain_type = semantics.JAVA_TOOLCHAIN_TYPE, + ) + +def _test_custom_singlejar(name): + _declare_java_toolchain(name = name) + + util.helper_target( + java_binary, + name = name + "/binary", + srcs = [name + "/main.java"], + main_class = "com.google.test.main", + ) + + analysis_test( + name = name, + impl = _test_custom_singlejar_impl, + target = name + "/binary", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + # Starlark rules are only used with Bazel 8 onwards. + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_custom_singlejar_impl(env, target): + action = env.expect.that_target(target).action_named("JavaDeployJar") + action.inputs().contains_at_least_predicates( + [ + matching.file_path_matches("*/test_custom_singlejar/binary.jar"), + ], + ) + +def deploy_archive_builder_test_suite(name): + """Test suite for java_binary deploy archive.""" + test_suite( + name = name, + tests = [ + _test_custom_singlejar, + ], + ) From 21e567b1543ce5af9b1654a167a69d7aabb3d0a9 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 3 Mar 2026 12:00:43 -0800 Subject: [PATCH 134/251] Remove JavaToolchainTest and add a Starlark test for java_common toolchain type enforcement. PiperOrigin-RevId: 878061671 Change-Id: Ie25a277183df5801c9f4909bbdc3f9ef3d20eb62 --- test/java/toolchains/java_toolchain_tests.bzl | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 9ca28577..7c95d0e3 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -6,6 +6,7 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") +load("//java/common:java_common.bzl", "java_common") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//java/toolchains:java_toolchain.bzl", "java_toolchain") @@ -566,6 +567,34 @@ def _test_javabuilder_location_expansion_with_multiple_artifacts_impl(env, targe "{package}/c {package}/d", ]).in_order() +def _no_toolchain_rule_impl(ctx): + java_common.pack_sources( + ctx.actions, + output_source_jar = "output_source_jar", + java_toolchain = "java_toolchain", + ) + +_no_toolchain_rule = rule( + implementation = _no_toolchain_rule_impl, +) + +def _test_java_common_without_toolchain_type_fails(name): + util.helper_target( + _no_toolchain_rule, + name = name + "/no_toolchain", + ) + analysis_test( + name = name, + impl = _test_java_common_without_toolchain_type_fails_impl, + target = name + "/no_toolchain", + expect_failure = True, + ) + +def _test_java_common_without_toolchain_type_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("must declare *tools/jdk:toolchain_type' toolchain in order to use java_common"), + ) + def java_toolchain_tests(name): test_suite( name = name, @@ -589,5 +618,6 @@ def java_toolchain_tests(name): _test_java_compile_action_exec_gets_javacopts_from_toolchain, _test_java_compile_action_uses_tool_specific_jvm_opts, _test_javabuilder_location_expansion_with_multiple_artifacts, + _test_java_common_without_toolchain_type_fails, ], ) From 27163ac1f0380ced234e0378456b89bf21418c2d Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 4 Mar 2026 09:42:56 -0800 Subject: [PATCH 135/251] Starlarkify coverage, annotation processing tests. PiperOrigin-RevId: 878534391 Change-Id: I72afb6f8e85dc85cdbede772efccc52d11669815 --- test/java/common/java_common_tests.bzl | 92 +++++++++++++++++++++ test/java/testutil/javac_action_subject.bzl | 1 + test/java/testutil/rules/custom_library.bzl | 2 + 3 files changed, 95 insertions(+) diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index 2eaf00de..c35f8388 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -1,5 +1,6 @@ """Tests for java_common APIs""" +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") @@ -11,6 +12,7 @@ load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_plugin_info.bzl", "JavaPluginInfo") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") load("//test/java/testutil:rules/custom_library.bzl", "custom_library") load("//test/java/testutil:rules/custom_library_extended_compile_jdeps.bzl", "CompileJdepsInfo", "custom_library_extended_jdeps") load("//test/java/testutil:rules/custom_library_with_additional_inputs.bzl", "custom_library_with_additional_inputs") @@ -788,6 +790,94 @@ def _test_compile_strict_deps_enum_impl(env, target): matching.str_matches("invalid value for strict_deps: FOO"), ) +def _test_java_library_collects_coverage_dependencies_from_resources(name): + util.helper_target( + cc_binary, + name = name + "/lib/jni.so", + srcs = [name + "/lib/jni.cc"], + linkshared = 1, + features = ["-supports_pic"], + ) + util.helper_target( + java_library, + name = name + "/lib", + resources = [name + "/lib/jni.so"], + ) + + analysis_test( + name = name, + impl = _test_java_library_collects_coverage_dependencies_from_resources_impl, + target = name + "/lib", + config_settings = { + "//command_line_option:collect_code_coverage": "true", + "//command_line_option:instrumentation_filter": "//test/...", + }, + ) + +def _test_java_library_collects_coverage_dependencies_from_resources_impl(env, target): + env.expect.that_target(target).provider( + InstrumentedFilesInfo, + ).instrumented_files().contains_exactly(["{package}/{name}/jni.cc"]) + + env.expect.that_target(target).provider( + InstrumentedFilesInfo, + ).metadata_files().contains_exactly(["{package}/_objs/{name}/jni.so/jni.gcno"]) + +def _test_skip_annotation_processing(name): + util.helper_target( + java_plugin, + name = name + "/processor", + srcs = [name + "/processor.java"], + data = [name + "/processor_data.txt"], + generates_api = True, # so Turbine would normally run it + processor_class = "Foo", + ) + util.helper_target( + java_library, + name = name + "/exports_processor", + exported_plugins = [":" + name + "/processor"], + ) + util.helper_target( + custom_library, + name = name + "/custom", + srcs = [name + "/custom.java"], + plugins = [":" + name + "/processor"], + deps = [":" + name + "/exports_processor"], + enable_annotation_processing = False, + ) + util.helper_target( + java_library, + name = name + "/custom_noproc", + srcs = [name + "/custom.java"], + ) + + analysis_test( + name = name, + impl = _test_skip_annotation_processing_impl, + targets = { + "custom": ":" + name + "/custom", + "custom_noproc": ":" + name + "/custom_noproc", + }, + ) + +def _test_skip_annotation_processing_impl(env, targets): + javac_action = javac_action_subject.of(env, targets.custom, "{package}/lib{name}.jar") + + javac_action.mnemonic().equals("Javac") + javac_action.argv().not_contains("--processors") + javac_action.argv().contains("--processorpath") + javac_action.inputs().contains_at_least_predicates([ + matching.file_basename_equals("processor_data.txt"), + ]) + + turbine_action = javac_action_subject.of(env, targets.custom, "{package}/lib{name}-hjar.jar") + turbine_action.mnemonic().equals("JavacTurbine") + turbine_action.argv().not_contains("--processors") + + turbine_action_noproc = javac_action_subject.of(env, targets.custom_noproc, "{package}/lib{name}-hjar.jar") + turbine_action_noproc.mnemonic().equals("Turbine") + turbine_action_noproc.argv().not_contains("--processors") + def java_common_tests(name): test_suite( name = name, @@ -817,5 +907,7 @@ def java_common_tests(name): _test_compile_neverlink, _test_compile_strict_deps_case_sensitivity, _test_compile_strict_deps_enum, + _test_java_library_collects_coverage_dependencies_from_resources, + _test_skip_annotation_processing, ], ) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index ed6e9fa2..3a105b70 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -26,6 +26,7 @@ def _new_javac_action_subject(env, target, output): executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, argv = action_subject.argv, + mnemonic = action_subject.mnemonic, ) return public diff --git a/test/java/testutil/rules/custom_library.bzl b/test/java/testutil/rules/custom_library.bzl index 024c05d9..ec3699ce 100644 --- a/test/java/testutil/rules/custom_library.bzl +++ b/test/java/testutil/rules/custom_library.bzl @@ -21,6 +21,7 @@ def _custom_library_impl(ctx): plugins = [p[JavaPluginInfo] for p in ctx.attr.plugins], javac_opts = ctx.attr.javac_opts, java_toolchain = semantics.find_java_toolchain(ctx), + enable_annotation_processing = ctx.attr.enable_annotation_processing, ) return [DefaultInfo(files = depset([output_jar])), compilation_provider] @@ -35,6 +36,7 @@ custom_library = rule( "plugins": attr.label_list(), "javac_opts": attr.string_list(), "neverlink": attr.bool(), + "enable_annotation_processing": attr.bool(default = True), }, toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], fragments = ["java"], From abda3d1472251220b30c070bc82054bd18526231 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 4 Mar 2026 11:56:56 -0800 Subject: [PATCH 136/251] Test that --experimental_strict_java_deps is passed down to the javac action PiperOrigin-RevId: 878599080 Change-Id: I0046d89faf8edecdacdddcbc2648aafc8179f71b --- test/java/common/rules/java_library_tests.bzl | 58 ++++++++++++++++--- test/java/testutil/javac_action_subject.bzl | 6 +- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index c6bb282a..64e17435 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -1,5 +1,6 @@ """Tests for the java_library rule""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") @@ -9,6 +10,7 @@ load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_info.bzl", "JavaInfo") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") load("//test/java/testutil:rules/forward_java_info.bzl", "java_info_forwarding_rule") load("//test/java/testutil:rules/wrap_java_info.bzl", "JavaInfoWrappingInfo", "java_info_wrapping_rule") @@ -309,15 +311,55 @@ def _test_exposes_native_library_info_impl(env, target): assert_lib.dynamic_library().basename().contains("mynativedep") +def _test_strict_java_deps(name, strict_java_deps): + util.helper_target( + java_library, + name = name + "/jl", + srcs = ["A.java"], + ) + + analysis_test( + name = name, + impl = _test_strict_java_deps_impl, + target = name + "/jl", + config_settings = {"//command_line_option:experimental_strict_java_deps": strict_java_deps}, + attrs = {"expected_strict_java_deps": attr.string()}, + attr_values = {"expected_strict_java_deps": strict_java_deps}, + ) + +def _test_strict_java_deps_impl(env, target): + # Note that if --experimental_strict_java_deps=OFF, we may not set --strict_java_deps in the + # javac action's argv at all; the "OFF" value (which is equivalent to an unset flag) in that + # case is injected by javac_action_subject for convenience and canonicalization. + expect_that_javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + expect_that_javac_action.strict_java_deps().contains_exactly([env.ctx.attr.expected_strict_java_deps]) + +def _test_strict_java_deps_off(name): + _test_strict_java_deps(name, "OFF") + +def _test_strict_java_deps_warn(name): + _test_strict_java_deps(name, "WARN") + +def _test_strict_java_deps_error(name): + _test_strict_java_deps(name, "ERROR") + def java_library_tests(name): + tests = [ + _test_exposes_plugins, + _test_exposes_java_info, + _test_java_info_propagation, + _test_java_library_attributes, + _test_propagates_direct_native_libraries, + _test_exposes_native_library_info, + ] + if bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + tests += [ + _test_strict_java_deps_off, + _test_strict_java_deps_warn, + _test_strict_java_deps_error, + ] + test_suite( name = name, - tests = [ - _test_exposes_plugins, - _test_exposes_java_info, - _test_java_info_propagation, - _test_java_library_attributes, - _test_propagates_direct_native_libraries, - _test_exposes_native_library_info, - ], + tests = tests, ) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 3a105b70..beb0ecbc 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -22,6 +22,8 @@ def _new_javac_action_subject(env, target, output): direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), javacopts = lambda: _create_subject_for_flag("--javacopts", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), + # An unset --strict_java_deps is equivalent to "OFF". + strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, @@ -56,9 +58,9 @@ def _parse_flags(argv): return flag_values -def _create_subject_for_flag(flag_name, parsed_flags, meta): +def _create_subject_for_flag(flag_name, parsed_flags, meta, default = None): """Helper to create a collection subject for a given flag.""" - return subjects.collection(parsed_flags[flag_name], meta.derive(flag_name), format = True) + return subjects.collection(parsed_flags.get(flag_name, default), meta.derive(flag_name), format = True) javac_action_subject = struct( of = _new_javac_action_subject, From e898c0fcc80f12f9fbe0e3e9e66f1d3e78ca378d Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Mar 2026 05:40:16 -0800 Subject: [PATCH 137/251] Prepare for Starlarkifying more `java_library` and `java_binary` tests (ignore-relnotes) PiperOrigin-RevId: 879015156 Change-Id: I3f1d0bcf272e21de4861096fa570d98ce461f7fa --- .../common_launcher_java_binary_tests.bzl | 28 +++++++++++++ .../common_launcher_java_library_tests.bzl | 27 +++++++++++++ test/java/common/rules/java_binary_tests.bzl | 17 +++++++- test/java/common/rules/java_library_tests.bzl | 39 +++++++++++++------ 4 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 test/java/common/rules/common_launcher_java_binary_tests.bzl create mode 100644 test/java/common/rules/common_launcher_java_library_tests.bzl diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl new file mode 100644 index 00000000..34c6e3f5 --- /dev/null +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -0,0 +1,28 @@ +"""Parameterized tests for java_binary with --java_launcher""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") + +def _test_java_binary_non_executable_rule_outputs(name): + util.helper_target( + java_binary, + name = name + "/test_app_noexec", + srcs = ["InputFile.java"], + create_executable = 0, + ) + + analysis_test( + name = name, + impl = _test_java_binary_non_executable_rule_outputs_impl, + target = name + "/test_app_noexec", + ) + +def _test_java_binary_non_executable_rule_outputs_impl(env, target): + env.expect.that_target(target).default_outputs().contains_exactly([ + "{package}/{name}.jar", + ]) + +JAVA_BINARY_LAUNCHER_TESTS = [ + _test_java_binary_non_executable_rule_outputs, +] diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl new file mode 100644 index 00000000..8f0ed228 --- /dev/null +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -0,0 +1,27 @@ +"""Parameterized tests for java_library with --java_launcher""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") + +def _test_java_library_rule_outputs(name): + util.helper_target( + java_library, + name = name + "/test_lib", + srcs = ["A.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_rule_outputs_impl, + target = name + "/test_lib", + ) + +def _test_java_library_rule_outputs_impl(env, target): + env.expect.that_target(target).default_outputs().contains_exactly([ + "{package}/lib{name}.jar", + ]) + +JAVA_LIBRARY_LAUNCHER_TESTS = [ + _test_java_library_rule_outputs, +] diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 10728fb3..7ee9eb1d 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -8,6 +8,7 @@ load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") +load("//test/java/common/rules:common_launcher_java_binary_tests.bzl", "JAVA_BINARY_LAUNCHER_TESTS") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -251,7 +252,7 @@ def _test_java_binary_can_set_transitive_validation_impl(env, targets): def java_binary_tests(name): test_suite( - name = name, + name = "_basic_" + name, tests = [ _test_java_binary_provides_binary_java_info, _test_stamp_conversion_does_not_override_int, @@ -261,3 +262,17 @@ def java_binary_tests(name): _test_java_binary_can_set_transitive_validation, ], ) + + # TODO: unset --java_launcher explicitly + test_suite( + name = "_jdk_launcher_" + name, + tests = JAVA_BINARY_LAUNCHER_TESTS, + ) + + native.test_suite( + name = name, + tests = [ + "_basic_" + name, + "_jdk_launcher_" + name, + ], + ) diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index 64e17435..77980f2f 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -9,6 +9,8 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_info.bzl", "JavaInfo") +load("//test/java/common/rules:common_launcher_java_library_tests.bzl", "JAVA_LIBRARY_LAUNCHER_TESTS") +load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -312,6 +314,10 @@ def _test_exposes_native_library_info_impl(env, target): assert_lib.dynamic_library().basename().contains("mynativedep") def _test_strict_java_deps(name, strict_java_deps): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + util.helper_target( java_library, name = name + "/jl", @@ -344,22 +350,31 @@ def _test_strict_java_deps_error(name): _test_strict_java_deps(name, "ERROR") def java_library_tests(name): - tests = [ - _test_exposes_plugins, - _test_exposes_java_info, - _test_java_info_propagation, - _test_java_library_attributes, - _test_propagates_direct_native_libraries, - _test_exposes_native_library_info, - ] - if bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: - tests += [ + test_suite( + name = "_basic_" + name, + tests = [ + _test_exposes_plugins, + _test_exposes_java_info, + _test_java_info_propagation, + _test_java_library_attributes, + _test_propagates_direct_native_libraries, + _test_exposes_native_library_info, _test_strict_java_deps_off, _test_strict_java_deps_warn, _test_strict_java_deps_error, - ] + ], + ) + # TODO: unset --java_launcher explicitly test_suite( + name = "_jdk_launcher_" + name, + tests = JAVA_LIBRARY_LAUNCHER_TESTS, + ) + + native.test_suite( name = name, - tests = tests, + tests = [ + "_basic_" + name, + "_jdk_launcher_" + name, + ], ) From 927f2914f8d01cc4f7376e8ffc6adaf76cec1f02 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Mar 2026 11:45:37 -0800 Subject: [PATCH 138/251] Migrate DeployArchiveBuilderTest.testGPlatformK8 PiperOrigin-RevId: 879173676 Change-Id: I7ef4839623ea1d441ddd46fb9863bba1ebee353a --- MODULE.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/MODULE.bazel b/MODULE.bazel index 204b8e88..442e7451 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -138,3 +138,4 @@ archive_override( test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) use_repo(test_repositories, "guava", "truth") + From 80a3bd663ada3931baf0492fb148ea102936c876 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Mar 2026 12:06:34 -0800 Subject: [PATCH 139/251] Fix rules_java CI broken by https://github.com/rules_java/bazel/commit/927f2914f8d01cc4f7376e8ffc6adaf76cec1f02 PiperOrigin-RevId: 879183729 Change-Id: I38a08618024abfb7678704075286a607775fb65d --- MODULE.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 442e7451..204b8e88 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -138,4 +138,3 @@ archive_override( test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) use_repo(test_repositories, "guava", "truth") - From dbefcf35b19047afc5bf08db38298f60142e7867 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Mar 2026 12:46:26 -0800 Subject: [PATCH 140/251] Starlarkify many `JavaStarlarkApiTest` tests. PiperOrigin-RevId: 879201973 Change-Id: I783eee85fb6f1beeb47781f7c163745c3c0b1984 --- test/java/common/java_common_tests.bzl | 201 ++++++++++++++++++ test/java/common/java_info_tests.bzl | 29 +++ test/java/testutil/java_info_subject.bzl | 1 + .../testutil/java_toolchain_info_subject.bzl | 5 + test/java/testutil/rules/custom_library.bzl | 4 + ...library_with_strict_java_deps_provider.bzl | 15 ++ ...library_with_wrong_java_toolchain_type.bzl | 24 +++ test/java/toolchains/BUILD | 2 + test/java/toolchains/java_toolchain_tests.bzl | 85 ++++++++ 9 files changed, 366 insertions(+) create mode 100644 test/java/testutil/rules/custom_library_with_strict_java_deps_provider.bzl create mode 100644 test/java/testutil/rules/custom_library_with_wrong_java_toolchain_type.bzl diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index c35f8388..d75d4a56 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -1,6 +1,8 @@ """Tests for java_common APIs""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") @@ -10,6 +12,7 @@ load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_common.bzl", "java_common") load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_plugin_info.bzl", "JavaPluginInfo") +load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") @@ -22,6 +25,8 @@ load("//test/java/testutil:rules/custom_library_with_exports.bzl", "custom_libra load("//test/java/testutil:rules/custom_library_with_named_outputs.bzl", "custom_library_with_named_outputs") load("//test/java/testutil:rules/custom_library_with_sourcepaths.bzl", "custom_library_with_sourcepaths") load("//test/java/testutil:rules/custom_library_with_strict_deps.bzl", "custom_library_with_strict_deps") +load("//test/java/testutil:rules/custom_library_with_strict_java_deps_provider.bzl", "StrictJavaDepsInfo", "custom_library_with_strict_java_deps_provider") +load("//test/java/testutil:rules/custom_library_with_wrong_java_toolchain_type.bzl", "custom_library_with_wrong_java_toolchain_type") load("//test/java/testutil:rules/custom_library_with_wrong_plugins_type.bzl", "custom_library_with_wrong_plugins_type") def _test_compile_default_values(name): @@ -878,6 +883,194 @@ def _test_skip_annotation_processing_impl(env, targets): turbine_action_noproc.mnemonic().equals("Turbine") turbine_action_noproc.argv().not_contains("--processors") +def _test_compile_direct_native_libraries(name): + target_name = name + "/custom" + util.helper_target( + cc_library, + name = target_name + "/native.so", + srcs = ["a.cc"], + ) + util.helper_target( + custom_library, + name = target_name, + srcs = ["A.java"], + ccdeps = [target_name + "/native.so"], + ) + + analysis_test( + name = name, + impl = _test_compile_direct_native_libraries_impl, + target = target_name, + ) + +def _test_compile_direct_native_libraries_impl(env, target): + assert_native_libs = java_info_subject.from_target(env, target).transitive_native_libraries() + assert_native_libs.static_libraries().contains_exactly_predicates([ + matching.any( + matching.str_matches("libnative.so.a"), # linux / mac + matching.str_matches("native.so.lib"), # windows + ), + ]) + +def _test_strict_java_deps_default(name): + util.helper_target( + custom_library, + name = name + "/unused", + ) + analysis_test( + name = name, + target = name + "/unused", # analysis_test requires setting a target. + impl = _test_strict_java_deps_default_impl, + fragments = ["java"], + ) + +def _test_strict_java_deps_default_impl(env, _unused): + env.expect.that_str(env.ctx.fragments.java.strict_java_deps).equals("default") + +def _test_strict_java_deps_error(name): + util.helper_target( + custom_library_with_strict_java_deps_provider, + name = name + "_strict_java_deps_provider", + ) + + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + analysis_test( + name = name, + impl = lambda env, target: env.expect.that_bool(True).equals(True), + target = name + "_strict_java_deps_provider", + ) + else: + analysis_test( + name = name, + target = name + "_strict_java_deps_provider", + impl = _test_strict_java_deps_error_impl, + fragments = ["java"], + config_settings = {"//command_line_option:experimental_strict_java_deps": "error"}, + ) + +def _test_strict_java_deps_error_impl(env, target): + env.expect.that_str(target[StrictJavaDepsInfo].strict_java_deps).equals("error") + +def _test_compile_output_jar_has_manifest_proto(name): + util.helper_target( + custom_library, + name = name + "/custom", + srcs = ["Main.java"], + ) + + analysis_test( + name = name, + impl = _test_compile_output_jar_has_manifest_proto_impl, + target = name + "/custom", + ) + +def _test_compile_output_jar_has_manifest_proto_impl(env, target): + java_info_subject.from_target(env, target).java_outputs().singleton().manifest_proto().short_path_equals( + "{package}/lib{name}.jar_manifest_proto", + ) + +def _test_compile_with_neverlink_deps(name): + target_name = name + "/custom" + util.helper_target( + java_library, + name = target_name + "/neverlink_dep", + srcs = ["B.java"], + neverlink = True, + ) + util.helper_target( + custom_library, + name = target_name, + srcs = ["A.java"], + deps = [target_name + "/neverlink_dep"], + ) + + analysis_test( + name = name, + impl = _test_compile_with_neverlink_deps_impl, + target = target_name, + ) + +def _test_compile_with_neverlink_deps_impl(env, target): + assert_java_info = java_info_subject.from_target(env, target) + assert_java_info.compilation_args().transitive_runtime_jars().contains_exactly([ + "{package}/lib{name}.jar", + ]) + assert_java_info.transitive_source_jars().contains_exactly([ + "{package}/lib{name}-src.jar", + "{package}/lib{name}/neverlink_dep-src.jar", + ]) + assert_java_info.compilation_args().transitive_compile_time_jars().contains_exactly([ + "{package}/lib{name}-hjar.jar", + "{package}/lib{name}/neverlink_dep-hjar.jar", + ]) + +def _test_compile_output_jar_not_in_runtime_path_without_sources_defined(name): + target_name = name + "/custom" + util.helper_target( + java_library, + name = target_name + "/export_dep", + srcs = ["B.java"], + ) + util.helper_target( + custom_library, + name = target_name, + srcs = [], + exports = [target_name + "/export_dep"], + ) + + analysis_test( + name = name, + impl = _test_compile_output_jar_not_in_runtime_path_without_sources_defined_impl, + target = target_name, + ) + +def _test_compile_output_jar_not_in_runtime_path_without_sources_defined_impl(env, target): + assert_java_info = java_info_subject.from_target(env, target) + assert_java_info.compilation_args().transitive_runtime_jars().contains_exactly([ + "{package}/lib{name}/export_dep.jar", + ]) + assert_java_info.compilation_args().transitive_compile_time_jars().contains_exactly([ + "{package}/lib{name}/export_dep-hjar.jar", + ]) + assert_java_info.java_outputs().singleton().class_jar().short_path_equals("{package}/lib{name}.jar") + assert_java_info.java_outputs().singleton().compile_jar().equals(None) + +def _test_java_runtime_provider_files(name): + # Create a rule that extracts JavaRuntimeInfo.files + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = ["a.txt"], + java_home = "foo/bar", + ) + + analysis_test( + name = name, + impl = _test_java_runtime_provider_files_impl, + target = name + "/jvm", + ) + +def _test_java_runtime_provider_files_impl(env, target): + env.expect.that_target(target).default_outputs().contains_exactly(["{package}/a.txt"]) + +def _test_custom_library_with_wrong_java_toolchain_type(name): + util.helper_target( + custom_library_with_wrong_java_toolchain_type, + name = name + "/custom", + srcs = ["a.java"], + ) + analysis_test( + name = name, + impl = _test_custom_library_with_wrong_java_toolchain_type_impl, + target = name + "/custom", + expect_failure = True, + ) + +def _test_custom_library_with_wrong_java_toolchain_type_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("got element of type ToolchainInfo, want JavaToolchainInfo"), + ) + def java_common_tests(name): test_suite( name = name, @@ -909,5 +1102,13 @@ def java_common_tests(name): _test_compile_strict_deps_enum, _test_java_library_collects_coverage_dependencies_from_resources, _test_skip_annotation_processing, + _test_compile_direct_native_libraries, + _test_strict_java_deps_default, + _test_strict_java_deps_error, + _test_compile_output_jar_has_manifest_proto, + _test_compile_with_neverlink_deps, + _test_compile_output_jar_not_in_runtime_path_without_sources_defined, + _test_java_runtime_provider_files, + _test_custom_library_with_wrong_java_toolchain_type, ], ) diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index 4f82d3eb..daea0485 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -1390,6 +1390,34 @@ def _java_common_compile_native_libraries_propagate_test_impl(env, target): matching.str_matches("*native_dep*"), ]) +def _test_merge_runtime_output_jars(name): + util.helper_target( + java_library, + name = name + "/a", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + ) + util.helper_target( + java_info_merge_rule, + name = name + "/merged", + deps = [name + "/a", name + "/b"], + ) + analysis_test( + name = name, + impl = _test_merge_runtime_output_jars_impl, + target = name + "/merged", + ) + +def _test_merge_runtime_output_jars_impl(env, target): + java_info_subject.from_target(env, target).runtime_output_jars().contains_exactly([ + "{package}/lib{test_name}/a.jar", + "{package}/lib{test_name}/b.jar", + ]) + def java_info_tests(name): test_suite( name = name, @@ -1438,5 +1466,6 @@ def java_info_tests(name): _java_common_merge_with_neverlink_test, _java_common_compile_with_neverlink_test, _java_common_compile_native_libraries_propagate_test, + _test_merge_runtime_output_jars, ], ) diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index 8471706f..f5ad9e9c 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -98,6 +98,7 @@ def _new_java_outputs_subject(java_output, meta): source_jars = lambda: subjects.depset_file(java_output.source_jars if hasattr(java_output.source_jars, "to_list") else depset(java_output.source_jars), meta.derive("source_jars")), jdeps = lambda: subjects.file(java_output.jdeps, meta.derive("jdeps")), compile_jdeps = lambda: subjects.file(java_output.compile_jdeps, meta.derive("compile_jdeps")), + manifest_proto = lambda: subjects.file(java_output.manifest_proto, meta.derive("manifest_proto")), native_headers_jar = lambda: subjects.file(java_output.native_headers_jar, meta.derive("native_headers_jar")), ) return public diff --git a/test/java/testutil/java_toolchain_info_subject.bzl b/test/java/testutil/java_toolchain_info_subject.bzl index 2757bfce..31afe59d 100644 --- a/test/java/testutil/java_toolchain_info_subject.bzl +++ b/test/java/testutil/java_toolchain_info_subject.bzl @@ -23,6 +23,11 @@ def _new_java_toolchain_info_subject(info, meta): header_compiler_builtin_processors = lambda: subjects.collection(info._header_compiler_builtin_processors.to_list(), meta.derive("_header_compiler_builtin_processors")), reduced_classpath_incompatible_processors = lambda: subjects.collection(info._reduced_classpath_incompatible_processors.to_list(), meta.derive("_reduced_classpath_incompatible_processors")), javabuilder = lambda: _new_java_builder_subject(info._javabuilder, meta.derive("_javabuilder")), + label = lambda: subjects.label(info.label, meta.derive("label")), + # TODO: hvd - Give label_subject predicate matching support so we don't need this str_subject variant. + label_str = lambda: subjects.str(str(info.label), meta.derive("label_str")), + default_javacopts = lambda: subjects.collection(info._javacopts_list, meta.derive("default_javacopts")), + default_javacopts_depset = lambda: subjects.collection(info._javacopts.to_list(), meta.derive("default_javacopts_depset")), ) return public diff --git a/test/java/testutil/rules/custom_library.bzl b/test/java/testutil/rules/custom_library.bzl index ec3699ce..5ef3ca03 100644 --- a/test/java/testutil/rules/custom_library.bzl +++ b/test/java/testutil/rules/custom_library.bzl @@ -1,5 +1,6 @@ """Helper rule for testing compilation with default parameter values""" +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("//java/common:java_common.bzl", "java_common") load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_plugin_info.bzl", "JavaPluginInfo") @@ -9,6 +10,7 @@ def _custom_library_impl(ctx): output_jar = ctx.actions.declare_file("lib" + ctx.label.name + ".jar") deps = [dep[JavaInfo] for dep in ctx.attr.deps] runtime_deps = [dep[JavaInfo] for dep in ctx.attr.runtime_deps] + native_libraries = [dep[CcInfo] for dep in ctx.attr.ccdeps] compilation_provider = java_common.compile( ctx, source_files = ctx.files.srcs, @@ -22,6 +24,7 @@ def _custom_library_impl(ctx): javac_opts = ctx.attr.javac_opts, java_toolchain = semantics.find_java_toolchain(ctx), enable_annotation_processing = ctx.attr.enable_annotation_processing, + native_libraries = native_libraries, ) return [DefaultInfo(files = depset([output_jar])), compilation_provider] @@ -32,6 +35,7 @@ custom_library = rule( "source_jars": attr.label_list(allow_files = [".jar"]), "deps": attr.label_list(), "runtime_deps": attr.label_list(), + "ccdeps": attr.label_list(providers = [CcInfo]), "exports": attr.label_list(), "plugins": attr.label_list(), "javac_opts": attr.string_list(), diff --git a/test/java/testutil/rules/custom_library_with_strict_java_deps_provider.bzl b/test/java/testutil/rules/custom_library_with_strict_java_deps_provider.bzl new file mode 100644 index 00000000..3a0f66a7 --- /dev/null +++ b/test/java/testutil/rules/custom_library_with_strict_java_deps_provider.bzl @@ -0,0 +1,15 @@ +"""Custom libraty that reads --strict_java_deps and returns it from a provider.""" + +StrictJavaDepsInfo = provider( + doc = "Provides args.strict_java_deps for testing", + fields = ["strict_java_deps"], +) + +def _impl(ctx): + return [StrictJavaDepsInfo(strict_java_deps = ctx.fragments.java.strict_java_deps)] + +custom_library_with_strict_java_deps_provider = rule( + implementation = _impl, + attrs = {}, + fragments = ["java"], +) diff --git a/test/java/testutil/rules/custom_library_with_wrong_java_toolchain_type.bzl b/test/java/testutil/rules/custom_library_with_wrong_java_toolchain_type.bzl new file mode 100644 index 00000000..73b4a7f9 --- /dev/null +++ b/test/java/testutil/rules/custom_library_with_wrong_java_toolchain_type.bzl @@ -0,0 +1,24 @@ +"""Custom rule to test java_common.compile(java_toolchain = ...) expects JavaToolchainInfo""" + +load("//java/common:java_common.bzl", "java_common") +load("//java/common:java_semantics.bzl", "semantics") + +def _impl(ctx): + output_jar = ctx.actions.declare_file("lib" + ctx.label.name + ".jar") + return java_common.compile( + ctx, + source_files = ctx.files.srcs, + output = output_jar, + java_toolchain = ctx.attr._java_toolchain[platform_common.ToolchainInfo], + ) + +custom_library_with_wrong_java_toolchain_type = rule( + implementation = _impl, + attrs = { + "srcs": attr.label_list(allow_files = [".java"]), + "deps": attr.label_list(), + "_java_toolchain": attr.label(default = semantics.JAVA_TOOLCHAIN_LABEL), + }, + toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], + fragments = ["java"], +) diff --git a/test/java/toolchains/BUILD b/test/java/toolchains/BUILD index 4ebe1f2d..1d7af21f 100644 --- a/test/java/toolchains/BUILD +++ b/test/java/toolchains/BUILD @@ -6,3 +6,5 @@ package(default_applicable_licenses = ["@rules_java//:license"]) java_runtime_tests(name = "java_runtime_tests") java_toolchain_tests(name = "java_toolchain_tests") + +exports_files(["java_runtime.src"]) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 7c95d0e3..372b9995 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -13,6 +13,7 @@ load("//java/toolchains:java_toolchain.bzl", "java_toolchain") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:java_toolchain_info_subject.bzl", "java_toolchain_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") +load("//toolchains:java_toolchain_alias.bzl", "java_toolchain_alias") def _declare_java_toolchain(*, name, **kwargs): java_runtime_name = name + "/runtime" @@ -595,6 +596,86 @@ def _test_java_common_without_toolchain_type_fails_impl(env, target): matching.str_matches("must declare *tools/jdk:toolchain_type' toolchain in order to use java_common"), ) +def _test_java_toolchain_flag_default(name): + util.helper_target( + java_toolchain_alias, + name = name + "/toolchain_alias", + ) + + analysis_test( + name = name, + impl = _test_java_toolchain_flag_default_impl, + target = name + "/toolchain_alias", + ) + +def _test_java_toolchain_flag_default_impl(env, target): + assert_toolchain = java_toolchain_info_subject.from_target(env, target) + assert_toolchain.label_str().matches( + matching.any( + matching.str_endswith("jdk:remote_toolchain"), + matching.str_endswith("jdk:toolchain"), + matching.str_endswith("jdk:toolchain_host"), + # buildifier: disable=canonical-repository + matching.str_startswith("@@//toolchains:toolchain_java"), + ), + ) + +def _test_java_toolchain_flag_set(name): + _declare_java_toolchain(name = name) + util.helper_target( + java_toolchain_alias, + name = name + "/toolchain_alias", + ) + + analysis_test( + name = name, + impl = _test_java_toolchain_flag_set_impl, + targets = { + "alias": name + "/toolchain_alias", + "toolchain": name + "/java_toolchain", + }, + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_java_toolchain_flag_set_impl(env, targets): + assert_toolchain = java_toolchain_info_subject.from_target(env, targets.alias) + assert_toolchain.label().equals(targets.toolchain.label) + +def _test_default_javac_opts_depset(name): + _declare_java_toolchain(name = name) + + analysis_test( + name = name, + impl = _test_default_javac_opts_depset_impl, + target = name + "/java_toolchain", + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_default_javac_opts_depset_impl(env, target): + java_toolchain_info_subject.from_target(env, target).default_javacopts_depset().contains_exactly( + ["-source 6 -target 6 -Xlint:toto -Xmaxerrs 500"], + ) + +def _test_default_javac_opts(name): + _declare_java_toolchain(name = name) + + analysis_test( + name = name, + impl = _test_default_javac_opts_impl, + target = name + "/java_toolchain", + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_default_javac_opts_impl(env, target): + java_toolchain_info_subject.from_target(env, target).default_javacopts().contains_at_least([ + "-source", + "6", + "-target", + "6", + ]).in_order() + def java_toolchain_tests(name): test_suite( name = name, @@ -619,5 +700,9 @@ def java_toolchain_tests(name): _test_java_compile_action_uses_tool_specific_jvm_opts, _test_javabuilder_location_expansion_with_multiple_artifacts, _test_java_common_without_toolchain_type_fails, + _test_java_toolchain_flag_default, + _test_java_toolchain_flag_set, + _test_default_javac_opts_depset, + _test_default_javac_opts, ], ) From 878ddc1d5246addd4231f105532c2ee2fe6e8977 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 5 Mar 2026 13:39:30 -0800 Subject: [PATCH 141/251] Starlarkify `*IsPrivateApi` tests in `JavaStarlarkApiTest`. PiperOrigin-RevId: 879224869 Change-Id: I6aacd6716aea4758ce6bb5de6a258c3800ba5808 --- test/java/common/java_common_tests.bzl | 56 ++++++++++++++++++ .../java/testutil/rules/private_api_usage.bzl | 57 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 test/java/testutil/rules/private_api_usage.bzl diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index d75d4a56..756e3a42 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -28,6 +28,7 @@ load("//test/java/testutil:rules/custom_library_with_strict_deps.bzl", "custom_l load("//test/java/testutil:rules/custom_library_with_strict_java_deps_provider.bzl", "StrictJavaDepsInfo", "custom_library_with_strict_java_deps_provider") load("//test/java/testutil:rules/custom_library_with_wrong_java_toolchain_type.bzl", "custom_library_with_wrong_java_toolchain_type") load("//test/java/testutil:rules/custom_library_with_wrong_plugins_type.bzl", "custom_library_with_wrong_plugins_type") +load("//test/java/testutil:rules/private_api_usage.bzl", "private_compile_api_usage", "private_merge_api_usage", "private_run_ijar_api_usage") def _test_compile_default_values(name): util.helper_target(custom_library, name = name + "/custom", srcs = ["Main.java"]) @@ -1071,6 +1072,52 @@ def _test_custom_library_with_wrong_java_toolchain_type_impl(env, target): matching.str_matches("got element of type ToolchainInfo, want JavaToolchainInfo"), ) +def _test_private_api(name, helper_rule, private_attr_name): + util.helper_target( + helper_rule, + name = name + "/custom", + private_attr_name = private_attr_name, + ) + + analysis_test( + name = name, + impl = lambda env, target: _test_private_api_impl(env, target, private_attr_name), + target = name + "/custom", + expect_failure = True, + ) + +def _test_private_api_impl(env, target, private_attr_name): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("got unexpected keyword argument: " + private_attr_name), + ) + +def _test_compile_disabling_compile_jar_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "enable_compile_jar_action") + +def _test_compile_classpath_resources_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "classpath_resources") + +def _test_compile_injecting_rule_kind_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "injecting_rule_kind") + +def _test_compile_enable_jspecify_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "enable_jspecify") + +def _test_merge_java_outputs_is_private_api(name): + _test_private_api(name, private_merge_api_usage, "merge_java_outputs") + +def _test_merge_source_jars_is_private_api(name): + _test_private_api(name, private_merge_api_usage, "merge_source_jars") + +def _test_compile_include_compilation_info_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "include_compilation_info") + +def _test_compile_resource_jars_is_private_api(name): + _test_private_api(name, private_compile_api_usage, "resource_jars") + +def _test_run_ijar_output_is_private_api(name): + _test_private_api(name, private_run_ijar_api_usage, "output") + def java_common_tests(name): test_suite( name = name, @@ -1110,5 +1157,14 @@ def java_common_tests(name): _test_compile_output_jar_not_in_runtime_path_without_sources_defined, _test_java_runtime_provider_files, _test_custom_library_with_wrong_java_toolchain_type, + _test_compile_disabling_compile_jar_is_private_api, + _test_compile_classpath_resources_is_private_api, + _test_compile_injecting_rule_kind_is_private_api, + _test_compile_enable_jspecify_is_private_api, + _test_merge_java_outputs_is_private_api, + _test_merge_source_jars_is_private_api, + _test_compile_include_compilation_info_is_private_api, + _test_compile_resource_jars_is_private_api, + _test_run_ijar_output_is_private_api, ], ) diff --git a/test/java/testutil/rules/private_api_usage.bzl b/test/java/testutil/rules/private_api_usage.bzl new file mode 100644 index 00000000..9ceaf826 --- /dev/null +++ b/test/java/testutil/rules/private_api_usage.bzl @@ -0,0 +1,57 @@ +"""Helper rules to test private API usage""" + +load("//java/common:java_common.bzl", "java_common") +load("//java/common:java_info.bzl", "JavaInfo") +load("//java/common:java_semantics.bzl", "semantics") + +_PRIVATE_ATTR_ATTRS = { + "private_attr_name": attr.string(mandatory = True), +} + +def _private_compile_api_impl(ctx): + out = ctx.actions.declare_file(ctx.label.name + ".jar") + java_common.compile( + ctx = ctx, + output = out, + java_toolchain = semantics.find_java_toolchain(ctx), + **{ctx.attr.private_attr_name: "does_not_matter"} + ) + return [] + +private_compile_api_usage = rule( + _private_compile_api_impl, + attrs = _PRIVATE_ATTR_ATTRS, + fragments = ["java"], + toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], +) + +def _private_merge_api_impl(ctx): + out = ctx.actions.declare_file(ctx.label.name + ".jar") + info = JavaInfo(output_jar = out, compile_jar = out) + java_common.merge( + providers = [info], + **{ctx.attr.private_attr_name: "does_not_matter"} + ) + return [] + +private_merge_api_usage = rule( + _private_merge_api_impl, + attrs = _PRIVATE_ATTR_ATTRS, + fragments = ["java"], +) + +def _private_run_ijar_api_impl(ctx): + java_common.run_ijar( + ctx.actions, + java_toolchain = semantics.find_java_toolchain(ctx), + jar = ctx.actions.declare_file(ctx.label.name + "_ijar.jar"), + **{ctx.attr.private_attr_name: "does_not_matter"} + ) + return [] + +private_run_ijar_api_usage = rule( + _private_run_ijar_api_impl, + attrs = _PRIVATE_ATTR_ATTRS, + fragments = ["java"], + toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], +) From 22bc9a886c1dcc5a44ef7d4e1ffe1afb1c816f3f Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 Mar 2026 01:40:24 -0700 Subject: [PATCH 142/251] Automatic code cleanup. PiperOrigin-RevId: 880722722 Change-Id: I55bf0687325a1ef5dac760adbe169d82fa000e9a --- java/common/rules/impl/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index 70adeccd..6ab41376 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -29,7 +29,7 @@ bzl_library( bzl_library( name = "java_helper_bzl", srcs = ["java_helper.bzl"], - visibility = ["//java:__subpackages__"], + visibility = ["//visibility:private"], deps = [ "//java/common:semantics_bzl", "//java/common/rules:java_helper_bzl", From 421776c58cd4ca3f75e852c63e570bf6a442c891 Mon Sep 17 00:00:00 2001 From: James Judd Date: Mon, 9 Mar 2026 07:41:17 -0700 Subject: [PATCH 143/251] 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 --- test/check_remote_java_tools_configs.sh | 6 ++- test/toolchains/bootclasspath_tests.bzl | 49 +++++++++++++++++++ toolchains/bootclasspath.bzl | 64 +++++++++++++++---------- 3 files changed, 92 insertions(+), 27 deletions(-) diff --git a/test/check_remote_java_tools_configs.sh b/test/check_remote_java_tools_configs.sh index 7e69dc00..957aa788 100755 --- a/test/check_remote_java_tools_configs.sh +++ b/test/check_remote_java_tools_configs.sh @@ -22,7 +22,11 @@ function download_and_check_hash() { TMP_FILE=$(mktemp -q /tmp/remotejavatools.XXXXXX) echo "fetching $name from $url to ${TMP_FILE}" curl --silent -o ${TMP_FILE} -L "$url" - actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1` + if command -v sha256sum &> /dev/null; then + actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1` + else + actual_hash=`shasum -a 256 ${TMP_FILE} | cut -d' ' -f1` + fi if [ "${hash}" != "${actual_hash}" ]; then echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" exit 1 diff --git a/test/toolchains/bootclasspath_tests.bzl b/test/toolchains/bootclasspath_tests.bzl index e7ad1cac..15ccd4ff 100644 --- a/test/toolchains/bootclasspath_tests.bzl +++ b/test/toolchains/bootclasspath_tests.bzl @@ -68,6 +68,53 @@ def _test_incompatible_language_version_bootclasspath_enabled_unversioned_impl(e system_path = target[java_common.BootClassPathInfo]._system_path env.expect.that_str(system_path).contains("local_jdk") +def _test_jdk8_uses_tree_artifact(name): + analysis_test( + name = name, + impl = _test_jdk8_uses_tree_artifact_impl, + target = Label("//toolchains:platformclasspath"), + config_settings = { + "//command_line_option:tool_java_runtime_version": "remotejdk_8", + }, + ) + +def _test_jdk8_uses_tree_artifact_impl(env, target): + env.expect.that_target(target).action_named( + "JavaToolchainCompileClasses", + ).argv().contains_at_least([ + "-d", + "{bindir}/{package}/{name}_classes", + "toolchains/DumpPlatformClassPath.java", + ]).in_order() + env.expect.that_target(target).action_named( + "JavaToolchainCompileBootClasspath", + ).argv().contains_at_least([ + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "-cp", + "{bindir}/{package}/{name}_classes", + "DumpPlatformClassPath", + "{bindir}/{package}/{name}_unstripped.jar", + ]).in_order() + +def _test_jdk11_uses_source_launcher(name): + analysis_test( + name = name, + impl = _test_jdk11_uses_source_launcher_impl, + target = Label("//toolchains:platformclasspath"), + config_settings = { + "//command_line_option:tool_java_runtime_version": "remotejdk_11", + }, + ) + +def _test_jdk11_uses_source_launcher_impl(env, target): + env.expect.that_target(target).action_named( + "JavaToolchainCompileBootClasspath", + ).argv().contains_at_least([ + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "toolchains/DumpPlatformClassPath.java", + "{bindir}/{package}/{name}_unstripped.jar", + ]).in_order() + def bootclasspath_tests(name): test_suite( name = name, @@ -76,5 +123,7 @@ def bootclasspath_tests(name): _test_incompatible_language_version_bootclasspath_disabled, _test_incompatible_language_version_bootclasspath_enabled_versioned, _test_incompatible_language_version_bootclasspath_enabled_unversioned, + _test_jdk8_uses_tree_artifact, + _test_jdk11_uses_source_launcher, ], ) diff --git a/toolchains/bootclasspath.bzl b/toolchains/bootclasspath.bzl index 93da5de8..256c032f 100644 --- a/toolchains/bootclasspath.bzl +++ b/toolchains/bootclasspath.bzl @@ -129,29 +129,35 @@ def _bootclasspath_impl(ctx): exec_javabase = ctx.attr.java_runtime_alias[java_common.JavaRuntimeInfo] env = ctx.attr._utf8_environment[Utf8EnvironmentInfo].environment - class_dir = ctx.actions.declare_directory("%s_classes" % ctx.label.name) - - args = ctx.actions.args() - args.add("-source") - args.add("8") - args.add("-target") - args.add("8") - args.add("-Xlint:-options") - args.add("-J-XX:-UsePerfData") - args.add("-d") - args.add_all([class_dir], expand_directories = False) - args.add(ctx.file.src) - - ctx.actions.run( - executable = "%s/bin/javac" % exec_javabase.java_home, - mnemonic = "JavaToolchainCompileClasses", - inputs = [ctx.file.src] + ctx.files.java_runtime_alias, - outputs = [class_dir], - arguments = [args], - env = env, - execution_requirements = _SUPPORTS_PATH_MAPPING, - use_default_shell_env = True, - ) + # If possible, use JDK 11+'s ability to run a single Java file to avoid a + # separate action to compile DumpPlatformClassPath. + use_source_launcher = exec_javabase.version >= 11 + + class_dir = None + if not use_source_launcher: + class_dir = ctx.actions.declare_directory("%s_classes" % ctx.label.name) + + args = ctx.actions.args() + args.add("-source") + args.add("8") + args.add("-target") + args.add("8") + args.add("-Xlint:-options") + args.add("-J-XX:-UsePerfData") + args.add("-d") + args.add_all([class_dir], expand_directories = False) + args.add(ctx.file.src) + + ctx.actions.run( + executable = "%s/bin/javac" % exec_javabase.java_home, + mnemonic = "JavaToolchainCompileClasses", + inputs = [ctx.file.src] + ctx.files.java_runtime_alias, + outputs = [class_dir], + arguments = [args], + env = env, + execution_requirements = _SUPPORTS_PATH_MAPPING, + use_default_shell_env = True, + ) unstripped_bootclasspath = ctx.actions.declare_file("%s_unstripped.jar" % ctx.label.name) @@ -161,8 +167,13 @@ def _bootclasspath_impl(ctx): args.add("--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED") args.add("--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED") args.add("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED") - args.add_all("-cp", [class_dir], expand_directories = False) - args.add("DumpPlatformClassPath") + + if use_source_launcher: + args.add(ctx.file.src) + else: + args.add_all("-cp", [class_dir], expand_directories = False) + args.add("DumpPlatformClassPath") + args.add(unstripped_bootclasspath) if ctx.attr.language_version_bootstrap_runtime: @@ -211,7 +222,8 @@ Rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:bootstrap_runti if len(system) != len(system_files): system = None - inputs = depset([class_dir] + ctx.files.java_runtime_alias, transitive = [any_javabase.files]) + classpath_input = ctx.file.src if use_source_launcher else class_dir + inputs = depset([classpath_input] + ctx.files.java_runtime_alias, transitive = [any_javabase.files]) ctx.actions.run( executable = str(exec_javabase.java_executable_exec_path), mnemonic = "JavaToolchainCompileBootClasspath", From cde9c8b5e0c9dfab364ff515d45e5871e5cda5fc Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 Mar 2026 08:59:28 -0700 Subject: [PATCH 144/251] Starlarkify some java runtime tests and one common test. PiperOrigin-RevId: 880883085 Change-Id: I6b2013aa8fba49136967563c349292f1ab098f91 --- test/java/common/rules/BUILD | 3 + test/java/common/rules/add_exports_tests.bzl | 39 +++++++++++ test/java/common/rules/merge_attrs_tests.bzl | 2 +- test/java/testutil/cc_info_subject.bzl | 13 ++++ .../testutil/java_runtime_info_subject.bzl | 14 ++++ test/java/toolchains/java_runtime_tests.bzl | 69 +++++++++++++++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 test/java/common/rules/add_exports_tests.bzl diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index cc2cd337..32870da7 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -1,3 +1,4 @@ +load(":add_exports_tests.bzl", "add_exports_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") @@ -21,3 +22,5 @@ java_library_tests(name = "java_library_tests") java_import_tests(name = "java_import_tests") java_test_tests(name = "java_test_tests") + +add_exports_tests(name = "add_exports_tests") diff --git a/test/java/common/rules/add_exports_tests.bzl b/test/java/common/rules/add_exports_tests.bzl new file mode 100644 index 00000000..482e7311 --- /dev/null +++ b/test/java/common/rules/add_exports_tests.bzl @@ -0,0 +1,39 @@ +"""Tests for the add_exports attribute""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:defs.bzl", "java_library") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:rules/java_info_merge.bzl", "java_info_merge_rule") + +def _test_merge_add_exports(name): + util.helper_target( + java_info_merge_rule, + name = name + "/merge", + deps = [name + "/a"], + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["A.java"], + add_exports = ["java.base/java.lang"], + ) + + analysis_test( + name = name, + impl = _test_merge_add_exports_impl, + target = name + "/merge", + ) + +def _test_merge_add_exports_impl(env, target): + java_info_subject.from_target(env, target).module_flags().add_exports().contains_exactly( + ["java.base/java.lang"], + ) + +def add_exports_tests(name): + test_suite( + name = name, + tests = [ + _test_merge_add_exports, + ], + ) diff --git a/test/java/common/rules/merge_attrs_tests.bzl b/test/java/common/rules/merge_attrs_tests.bzl index 84b340e3..bea71adc 100644 --- a/test/java/common/rules/merge_attrs_tests.bzl +++ b/test/java/common/rules/merge_attrs_tests.bzl @@ -1,4 +1,4 @@ -"""Tests for merge_attrsfunction""" +"""Tests for merge_attrs function""" load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") load( diff --git a/test/java/testutil/cc_info_subject.bzl b/test/java/testutil/cc_info_subject.bzl index 2d7dca12..b50ff2e6 100644 --- a/test/java/testutil/cc_info_subject.bzl +++ b/test/java/testutil/cc_info_subject.bzl @@ -22,6 +22,7 @@ def _new_cc_info_linking_context_subject(cc_info, meta): public = struct( equals = lambda other: _cc_info_linking_context_equals(self.actual, other, self.meta), library_files = lambda: _new_library_files_subject(self.actual, self.meta), + static_library_files = lambda: _new_static_library_files_subject(self.actual, self.meta), ) return public @@ -43,6 +44,17 @@ def _new_library_files_subject(linking_context, meta): meta = meta.derive("library_files"), ) +def _new_static_library_files_subject(linking_context, meta): + static_libraries = [] + for input in linking_context.linker_inputs.to_list(): + for lib in input.libraries: + if lib.static_library: + static_libraries.append(lib.static_library) + return subjects.depset_file( + depset(static_libraries), + meta = meta.derive("static_library_files"), + ) + def _cc_info_linking_context_equals(actual, expected, meta): if actual == expected: return @@ -87,6 +99,7 @@ def _get_singleton(seq): return seq[0] cc_info_subject = struct( + new_from_cc_info = _new_cc_info_subject, new_from_java_info = lambda java_info, meta: _new_cc_info_subject(java_info.cc_link_params_info, meta.derive("cc_link_params_info")), libraries_to_link = _new_cc_info_libraries_to_link_subject, ) diff --git a/test/java/testutil/java_runtime_info_subject.bzl b/test/java/testutil/java_runtime_info_subject.bzl index ad68fead..bb6ae52c 100644 --- a/test/java/testutil/java_runtime_info_subject.bzl +++ b/test/java/testutil/java_runtime_info_subject.bzl @@ -3,6 +3,7 @@ load("@rules_testing//lib:truth.bzl", "subjects", "truth") load("@rules_testing//lib:util.bzl", "TestingAspectInfo") load("//java/common:java_common.bzl", "java_common") +load(":cc_info_subject.bzl", "cc_info_subject") def _new_java_runtime_info_subject(java_runtime_info, meta): self = struct( @@ -10,11 +11,19 @@ def _new_java_runtime_info_subject(java_runtime_info, meta): meta = meta.derive("JavaRuntimeInfo"), ) public = struct( + hermetic_static_libs = lambda: _new_hermetic_static_libs_subject(self.actual.hermetic_static_libs, self.meta.derive("hermetic_static_libs")), java_home = lambda: _new_path_string_subject(self.actual.java_home, self.meta.derive("java_home")), java_home_runfiles_path = lambda: _new_path_string_subject(self.actual.java_home_runfiles_path, self.meta.derive("java_home_runfiles_path")), java_executable_exec_path = lambda: _new_path_string_subject(self.actual.java_executable_exec_path, self.meta.derive("java_executable_exec_path")), java_executable_runfiles_path = lambda: _new_path_string_subject(self.actual.java_executable_runfiles_path, self.meta.derive("java_executable_runfiles_path")), files = lambda: subjects.depset_file(self.actual.files, self.meta.derive("files")), + lib_ct_sym = lambda: subjects.file(self.actual.lib_ct_sym, self.meta.derive("lib_ct_sym")), + ) + return public + +def _new_hermetic_static_libs_subject(hermetic_static_libs, meta): + public = struct( + singleton = lambda: cc_info_subject.new_from_cc_info(_get_singleton(hermetic_static_libs), meta.derive("cc_info")), ) return public @@ -46,6 +55,11 @@ def _from_target(env, target): ), ) +def _get_singleton(seq): + if len(seq) != 1: + fail("expected singleton, got:", seq) + return seq[0] + java_runtime_info_subject = struct( new = _new_java_runtime_info_subject, from_target = _from_target, diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 5ec2a061..0112b172 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -1,5 +1,6 @@ """Tests for the java_runtime rule""" +load("@rules_cc//cc:defs.bzl", "cc_import") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") @@ -353,6 +354,71 @@ def _test_java_home_generated_impl(env, target): "{gendir}/{package}/generated_java_home", ) +def _test_hermetic_static_libs(name): + util.helper_target( + cc_import, + name = name + "/libs", + static_library = "libStatic.a", + ) + util.helper_target( + java_runtime, + name = name + "/jvm", + lib_modules = name + "/gen_lib_modules", + hermetic_srcs = [name + "/hermetic.properties"], + hermetic_static_libs = [name + "/libs"], + ) + + analysis_test( + name = name, + impl = _test_hermetic_static_libs_impl, + target = name + "/jvm", + ) + +def _test_hermetic_static_libs_impl(env, target): + cc_info = java_runtime_info_subject.from_target(env, target).hermetic_static_libs().singleton() + cc_info.linking_context().static_library_files().contains_exactly(["{package}/libStatic.a"]) + +def _test_implicit_lib_ct_sym(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = [ + name + "/java", + name + "/jvm/implicit/lib/ct.sym", + ], + ) + analysis_test( + name = name, + impl = _test_implicit_lib_ct_sym_impl, + target = name + "/jvm", + ) + +def _test_implicit_lib_ct_sym_impl(env, target): + java_runtime_info_subject.from_target(env, target).lib_ct_sym().short_path_equals( + "{package}/{name}/implicit/lib/ct.sym", + ) + +def _test_explicit_lib_ct_sym(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = [ + name + "/java", + name + "/jvm/implicit/lib/ct.sym", + ], + lib_ct_sym = name + "/jvm/explicit/lib/ct.sym", + ) + analysis_test( + name = name, + impl = _test_explicit_lib_ct_sym_impl, + target = name + "/jvm", + ) + +def _test_explicit_lib_ct_sym_impl(env, target): + java_runtime_info_subject.from_target(env, target).lib_ct_sym().short_path_equals( + "{package}/{name}/explicit/lib/ct.sym", + ) + def java_runtime_tests(name): test_suite( name = name, @@ -371,5 +437,8 @@ def java_runtime_tests(name): _test_make_variables, _test_no_srcs, _test_java_home_generated, + _test_hermetic_static_libs, + _test_implicit_lib_ct_sym, + _test_explicit_lib_ct_sym, ], ) From b4301859e168f15a58d36fda9009f1f1efca81a4 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 Mar 2026 09:29:32 -0700 Subject: [PATCH 145/251] Remove deleted pipeline from `README.md` (ignore-relnotes) PiperOrigin-RevId: 880896423 Change-Id: I82f17552123b20d17a3cfc8f9ec23d4443c96197 --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 52be4f9d..c9d62dc2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # rules_java -* Postsubmit [![Build status](https://badge.buildkite.com/d4f950ef5f481b8ca066624ba06c238fa1446d84a057ddbf89.svg?branch=master)](https://buildkite.com/bazel/rules-java-java) -* Postsubmit + Current Bazel Incompatible Flags [![Build status](https://badge.buildkite.com/ef265d270238c02aff65106a0b861abb9265efacdf4af399c3.svg?branch=master)](https://buildkite.com/bazel/rules-java-plus-bazelisk-migrate) +[![Build status](https://badge.buildkite.com/d4f950ef5f481b8ca066624ba06c238fa1446d84a057ddbf89.svg?branch=master)](https://buildkite.com/bazel/rules-java-java) Java Rules for Bazel https://bazel.build. @@ -22,6 +21,6 @@ Add a load like: ```build load("@rules_java//java:java_library.bzl", "java_library") ``` -to your `BUILD` / `BUILD.bazel` / bzl` files +to your `BUILD` / `BUILD.bazel` / `*.bzl` files For detailed docs on the core rules, see https://bazel.build/reference/be/java From cfa04565277c6a1d0f13979621efaf412455ef08 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Mar 2026 06:33:32 -0700 Subject: [PATCH 146/251] Implement the easy java_test unit tests in Starlark. PiperOrigin-RevId: 881395705 Change-Id: I63ec4d6489a15fd854b75176a3a216e715bded6a --- test/java/bazel/rules/BUILD.bazel | 3 + test/java/bazel/rules/java_test_tests.bzl | 44 ++++++ test/java/common/rules/java_test_tests.bzl | 159 +++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 test/java/bazel/rules/java_test_tests.bzl diff --git a/test/java/bazel/rules/BUILD.bazel b/test/java/bazel/rules/BUILD.bazel index 01655c20..6f97d15a 100644 --- a/test/java/bazel/rules/BUILD.bazel +++ b/test/java/bazel/rules/BUILD.bazel @@ -1,9 +1,12 @@ load(":java_binary_tests.bzl", "java_binary_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") +load(":java_test_tests.bzl", "java_test_tests") java_binary_tests(name = "java_binary_tests") java_library_tests(name = "java_library_tests") java_plugin_tests(name = "java_plugin_tests") + +java_test_tests(name = "java_test_tests") diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl new file mode 100644 index 00000000..9ee618d8 --- /dev/null +++ b/test/java/bazel/rules/java_test_tests.bzl @@ -0,0 +1,44 @@ +"""Tests for the Bazel java_test rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching", "subjects") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_test.bzl", "java_test") + +def _test_deduced_test_class(name): + util.helper_target( + java_test, + name = name + "/foo", + srcs = [name + "/Foo.java"], + ) + + analysis_test( + name = name, + impl = _test_deduced_test_class_impl, + target = name + "/foo", + ) + +def _test_deduced_test_class_impl(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + assert_action = env.expect.that_target(target).action_generating(executable) + + if assert_action.actual.substitutions: + # TemplateExpansion action on linux/mac + assert_jvm_flags = assert_action.substitutions().get( + "%jvm_flags%", + factory = lambda v, meta: subjects.collection([v], meta), + ) + else: + # Windows + assert_jvm_flags = assert_action.argv() + assert_jvm_flags.contains_predicate( + matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.foo"), + ) + +def java_test_tests(name): + test_suite( + name = name, + tests = [ + _test_deduced_test_class, + ], + ) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index f4db104b..13362dc3 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -1,5 +1,6 @@ """Tests for the java_test rule""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") @@ -7,8 +8,86 @@ load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") +load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") +def _test_java_test_is_test_only(name): + util.helper_target( + java_test, + name = name + "/test", + srcs = [name + "/Test.java"], + ) + + util.helper_target( + java_library, + name = name + "/lib", + srcs = [name + "/Lib.java"], + deps = [name + "/test"], + ) + + analysis_test( + name = name, + impl = _test_java_test_is_test_only_impl, + target = name + "/lib", + expect_failure = True, + ) + +def _test_java_test_is_test_only_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("non-test target '*/lib' depends on testonly target '*/test'"), + ) + +def _test_deps_without_srcs_fails(name): + util.helper_target( + rule = java_library, + name = name + "/lib", + srcs = [name + "/Lib.java"], + ) + + util.helper_target( + rule = java_test, + name = name + "/test", + deps = [name + "/lib"], + ) + + analysis_test( + name = name, + target = name + "/test", + impl = _test_deps_without_srcs_fails_impl, + expect_failure = True, + ) + +def _test_deps_without_srcs_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("deps not allowed without srcs"), + ) + +def _test_fix_deps_tool(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + util.helper_target( + rule = java_test, + name = name + "/test", + srcs = [name + "/Test.java"], + ) + + analysis_test( + name = name, + target = name + "/test", + impl = _test_fix_deps_tool_impl, + config_settings = { + "//command_line_option:experimental_fix_deps_tool": "customfixer", + }, + ) + +def _test_fix_deps_tool_impl(env, target): + assert_compile_action = env.expect.that_target(target).action_named("Javac") + assert_compile_action.argv().contains_at_least([ + "--experimental_fix_deps_tool", + "customfixer", + ]).in_order() + def _test_java_test_propagates_direct_native_libraries(name): util.helper_target( cc_library, @@ -74,10 +153,90 @@ def _test_java_test_propagates_direct_native_libraries_impl(env, target): matching.str_matches("-Djava.library.path=${JAVA_RUNFILES}/*/test_java_test_propagates_direct_native_libraries"), ) +def _test_coverage_uses_coverage_runner_for_main(name): + util.helper_target( + rule = java_test, + name = name + "/test", + srcs = [name + "/Test.java"], + ) + + analysis_test( + name = name, + impl = _test_coverage_uses_coverage_runner_for_main_impl, + target = name + "/test", + config_settings = { + "//command_line_option:collect_code_coverage": True, + }, + ) + +def _test_coverage_uses_coverage_runner_for_main_impl(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + assert_action = env.expect.that_target(target).action_generating(executable) + if assert_action.actual.substitutions: + assert_java_start_class = assert_action.substitutions().get( + "%java_start_class%", + factory = lambda v, meta: subjects.str(v, meta.derive("java_start_class")), + ) + assert_java_start_class.contains("com.google.testing.coverage.JacocoCoverageRunner") + else: + # Windows + assert_java_start_class = assert_action.argv() + assert_java_start_class.contains("java_start_class=com.google.testing.coverage.JacocoCoverageRunner") + +def _test_stamp_values(name): + util.helper_target( + rule = java_test, + name = name + "/stamp_true", + srcs = [name + "/Test.java"], + stamp = True, + ) + + util.helper_target( + rule = java_test, + name = name + "/stamp_false", + srcs = [name + "/Test.java"], + stamp = False, + ) + + util.helper_target( + rule = java_test, + name = name + "/stamp_auto", + srcs = [name + "/Test.java"], + stamp = -1, + ) + + util.helper_target( + rule = java_test, + name = name + "/stamp_default", + srcs = [name + "/Test.java"], + ) + + analysis_test( + name = name, + targets = { + "stamp": name + "/stamp_true", + "nostamp": name + "/stamp_false", + "autostamp": name + "/stamp_auto", + "defaultstamp": name + "/stamp_default", + }, + impl = _test_stamp_values_impl, + ) + +def _test_stamp_values_impl(env, targets): + env.expect.that_target(targets.stamp).attr("stamp", factory = subjects.int).equals(1) + env.expect.that_target(targets.nostamp).attr("stamp", factory = subjects.int).equals(0) + env.expect.that_target(targets.defaultstamp).attr("stamp", factory = subjects.int).equals(0) + env.expect.that_target(targets.autostamp).attr("stamp", factory = subjects.int).equals(-1) + def java_test_tests(name): test_suite( name = name, tests = [ + _test_java_test_is_test_only, + _test_deps_without_srcs_fails, + _test_fix_deps_tool, _test_java_test_propagates_direct_native_libraries, + _test_coverage_uses_coverage_runner_for_main, + _test_stamp_values, ], ) From 0508ac3d647638dbd8b59d4d54f43dfb89f65f00 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Mar 2026 07:16:51 -0700 Subject: [PATCH 147/251] Support embedding stamping info from bazel in `java_single_jar` A new attribute `stamp` controls the Bazel build info included in the output: - `stamp = 1`: Always embed Bazel build information, even in `--nostamp` builds. - `stamp = 0`: Embed Bazel build information with constant values even in `--stamp` builds. - `stamp = -1`: Embedding of Bazel build information is controlled by the `--[no]stamp` flag. The above only takes effect when `exclude_build_data = False` (default is `True`). It is an error to specify `stamp = 1` without `exclude_build_data = False`. Fixes https://github.com/bazelbuild/rules_java/issues/352 PiperOrigin-RevId: 881412734 Change-Id: I876b3a3b328eb363ad112dfc0fdfe599de03b164 --- MODULE.bazel | 9 +- java/common/BUILD | 4 +- java/common/rules/BUILD | 6 +- java/common/rules/impl/BUILD | 2 +- .../rules/impl/java_binary_deploy_jar.bzl | 11 +- java/common/rules/impl/java_helper.bzl | 10 ++ java/common/rules/java_single_jar.bzl | 25 ++- test/java/common/rules/BUILD | 3 + .../common/rules/java_single_jar_tests.bzl | 164 ++++++++++++++++++ 9 files changed, 210 insertions(+), 24 deletions(-) create mode 100644 test/java/common/rules/java_single_jar_tests.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 204b8e88..e98ca3d1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,14 +6,7 @@ module( ) bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "rules_cc", version = "0.2.13") -archive_override( - module_name = "rules_cc", - integrity = "sha256-y3RA9zEyB7HqBXVTgrlFmvfJARcEDzILe2ugNGC4ZrE=", - strip_prefix = "rules_cc-b5a65591334f74371f4d75003768957a740cd868", - urls = ["https://github.com/bazelbuild/rules_cc/archive/b5a65591334f74371f4d75003768957a740cd868.tar.gz"], -) - +bazel_dep(name = "rules_cc", version = "0.2.17") bazel_dep(name = "bazel_features", version = "1.30.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf") diff --git a/java/common/BUILD b/java/common/BUILD index 9958a883..9881236a 100644 --- a/java/common/BUILD +++ b/java/common/BUILD @@ -36,9 +36,7 @@ bzl_library( name = "semantics_bzl", srcs = ["java_semantics.bzl"], visibility = ["//visibility:public"], - deps = [ - "@rules_cc//cc/common", - ], + deps = ["@rules_cc//cc/common:cc_helper_bzl"], ) bzl_library( diff --git a/java/common/rules/BUILD b/java/common/rules/BUILD index f6fde9d4..4c24d073 100644 --- a/java/common/rules/BUILD +++ b/java/common/rules/BUILD @@ -35,7 +35,11 @@ bzl_library( name = "java_single_jar_bzl", srcs = ["java_single_jar.bzl"], visibility = ["//java:__subpackages__"], - deps = ["//java/common"], + deps = [ + "//java/common", + "//java/common:semantics_bzl", + "//java/common/rules/impl:java_helper_bzl", + ], ) bzl_library( diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index 6ab41376..70adeccd 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -29,7 +29,7 @@ bzl_library( bzl_library( name = "java_helper_bzl", srcs = ["java_helper.bzl"], - visibility = ["//visibility:private"], + visibility = ["//java:__subpackages__"], deps = [ "//java/common:semantics_bzl", "//java/common/rules:java_helper_bzl", diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index 7b7d69d1..d6add141 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -19,15 +19,6 @@ load(":java_helper.bzl", "helper") # copybara: default visibility -def _get_build_info(ctx, stamp): - if helper.is_stamping_enabled(ctx, stamp): - # Makes the target depend on BUILD_INFO_KEY, which helps to discover stamped targets - # See b/326620485 for more details. - ctx.version_file # buildifier: disable=no-effect - return ctx.attr._build_info_translator[OutputGroupInfo].non_redacted_build_info_files.to_list() - else: - return ctx.attr._build_info_translator[OutputGroupInfo].redacted_build_info_files.to_list() - def create_deploy_archives( ctx, java_attrs, @@ -70,7 +61,7 @@ def create_deploy_archives( order = "preorder", ) multi_release = ctx.fragments.java.multi_release_deploy_jars - build_info_files = _get_build_info(ctx, ctx.attr.stamp) + build_info_files = helper.get_build_info(ctx, ctx.attr.stamp) build_target = str(ctx.label) manifest_lines = ctx.attr.deploy_manifest_lines + extra_manifest_lines create_deploy_archive( diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index e45fac9d..638878ba 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -241,6 +241,15 @@ def _is_stamping_enabled(ctx, stamp): # stamp == -1 / auto return int(ctx.configuration.stamp_binaries()) +def _get_build_info(ctx, stamp): + if helper.is_stamping_enabled(ctx, stamp): + # Makes the target depend on BUILD_INFO_KEY, which helps to discover stamped targets + # See b/326620485 for more details. + ctx.version_file # buildifier: disable=no-effect + return ctx.attr._build_info_translator[OutputGroupInfo].non_redacted_build_info_files.to_list() + else: + return ctx.attr._build_info_translator[OutputGroupInfo].redacted_build_info_files.to_list() + helper = struct( collect_all_targets_as_deps = _collect_all_targets_as_deps, filter_launcher_for_target = _filter_launcher_for_target, @@ -265,6 +274,7 @@ helper = struct( detokenize_javacopts = _loading_phase_helper.detokenize_javacopts, tokenize_javacopts = _loading_phase_helper.tokenize_javacopts, is_stamping_enabled = _is_stamping_enabled, + get_build_info = _get_build_info, get_relative = _loading_phase_helper.get_relative, has_target_constraints = _loading_phase_helper.has_target_constraints, ) diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl index 95b7ca2e..c9552755 100644 --- a/java/common/rules/java_single_jar.bzl +++ b/java/common/rules/java_single_jar.bzl @@ -15,6 +15,8 @@ load("//java/common:java_common.bzl", "java_common") load("//java/common:java_info.bzl", "JavaInfo") +load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules/impl:java_helper.bzl", "helper") # copybara: default visibility @@ -69,8 +71,15 @@ def _bazel_java_single_jar_impl(ctx): else: fail("\"compress\" attribute (%s) must be: yes, no, preserve." % ctx.attr.compress) + if ctx.attr.exclude_build_data and ctx.attr.stamp == 1: + fail("Enabling stamping has not effect with exclude_build_data enabled") + + build_info_files = [] if ctx.attr.exclude_build_data: args.add("--exclude_build_data") + else: + build_info_files = helper.get_build_info(ctx, ctx.attr.stamp) + args.add_all(build_info_files, before_each = "--build_info_file") if ctx.attr.multi_release: args.add("--multi_release") @@ -78,7 +87,7 @@ def _bazel_java_single_jar_impl(ctx): args.add("--exclude_pattern", ctx.attr.exclude_pattern) ctx.actions.run( - inputs = inputs, + inputs = depset(build_info_files, transitive = [inputs]), outputs = [ctx.outputs.output], arguments = [args], progress_message = "Merging into %s" % ctx.outputs.output.short_path, @@ -138,6 +147,20 @@ bazel_java_single_jar = rule( executable = True, ), "output": attr.output(), + "stamp": attr.int( + doc = """ + Whether to embed extra Bazel build information into the build_data.properties file: + * `stamp = 1`: Always embed Bazel build information, even in `--nostamp` builds. + * `stamp = 0`: Embed Bazel build information with constant values, even in `--stamp` builds. + * `stamp = -1`: Embedding of Bazel build information is controlled by the `--[no]stamp` flag. + + Note: whether the output contains the build_data.properties file is controlled + by the `exclude_build_data` attribute. + """, + default = 0, + values = [-1, 0, 1], + ), + "_build_info_translator": attr.label(default = semantics.BUILD_INFO_TRANSLATOR_LABEL), }, implementation = _bazel_java_single_jar_impl, doc = """ diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 32870da7..8e74a2a0 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -4,6 +4,7 @@ load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") +load(":java_single_jar_tests.bzl", "java_single_jar_tests") load(":java_test_tests.bzl", "java_test_tests") load(":merge_attrs_tests.bzl", "merge_attrs_test_suite") @@ -21,6 +22,8 @@ java_library_tests(name = "java_library_tests") java_import_tests(name = "java_import_tests") +java_single_jar_tests(name = "java_single_jar_tests") + java_test_tests(name = "java_test_tests") add_exports_tests(name = "add_exports_tests") diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl new file mode 100644 index 00000000..8ea43da8 --- /dev/null +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -0,0 +1,164 @@ +"""Tests for the java_single_jar rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_single_jar.bzl", "java_single_jar") +load("//java/common:java_semantics.bzl", "semantics") + +def _label_to_bin_path(label): + segments = ["{bindir}"] + if label.repo_name: + segments.extend(["external", label.repo_name]) + segments.append(label.package) + return "/".join(segments) + +_BUILD_INFO_PATH = _label_to_bin_path(Label(semantics.BUILD_INFO_TRANSLATOR_LABEL)) + +def _test_java_single_jar_basic(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + deps = ["1.jar", "2.jar"], + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_basic_impl, + target = name + "/jar", + ) + +def _test_java_single_jar_basic_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.argv().contains_at_least([ + "--sources", + "{package}/1.jar", + "{package}/2.jar", + "--output", + "{bindir}/{package}/{name}.jar", + "--normalize", + "--dont_change_compression", + "--exclude_build_data", + "--multi_release", + ]).in_order() + +def _test_java_single_jar_force_enable_stamping(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + stamp = 1, + exclude_build_data = False, + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_force_enable_stamping_impl, + target = name + "/jar", + ) + +def _test_java_single_jar_force_enable_stamping_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.contains_flag_values([ + ("--build_info_file", _BUILD_INFO_PATH + "/non_volatile_file.properties"), + ("--build_info_file", _BUILD_INFO_PATH + "/volatile_file.properties"), + ]) + +def _test_java_single_jar_force_disable_stamping(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + stamp = 0, + exclude_build_data = False, + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_force_disable_stamping_impl, + target = name + "/jar", + ) + +def _test_java_single_jar_force_disable_stamping_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.contains_flag_values([ + ("--build_info_file", _BUILD_INFO_PATH + "/redacted_file.properties"), + ]) + +def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + stamp = 1, + exclude_build_data = True, + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_stamping_enabled_build_data_excluded_fails_impl, + target = name + "/jar", + expect_failure = True, + ) + +def _test_java_single_jar_stamping_enabled_build_data_excluded_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("Enabling stamping has not effect with exclude_build_data enabled"), + ) + +def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + stamp = -1, + exclude_build_data = False, + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl, + target = name + "/jar", + config_settings = { + "//command_line_option:stamp": True, + }, + ) + +def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.contains_flag_values([ + ("--build_info_file", _BUILD_INFO_PATH + "/non_volatile_file.properties"), + ("--build_info_file", _BUILD_INFO_PATH + "/volatile_file.properties"), + ]) + +def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + stamp = -1, + exclude_build_data = False, + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl, + target = name + "/jar", + config_settings = { + "//command_line_option:stamp": False, + }, + ) + +def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.contains_flag_values([ + ("--build_info_file", _BUILD_INFO_PATH + "/redacted_file.properties"), + ]) + +def java_single_jar_tests(name): + test_suite( + name = name, + tests = [ + _test_java_single_jar_basic, + _test_java_single_jar_force_enable_stamping, + _test_java_single_jar_force_disable_stamping, + _test_java_single_jar_stamping_enabled_build_data_excluded_fails, + _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled, + _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled, + ], + ) From 123b37028abe4ae6913c7a10a079f84d6c70e517 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 11 Mar 2026 05:33:31 -0700 Subject: [PATCH 148/251] Improve tests added in https://github.com/bazelbuild/rules_java/commit/0508ac3d647638dbd8b59d4d54f43dfb89f65f00 Replace the bespoke label -> file paths conversion with actual artifacts from the build info rule. (ignore-relnotes) PiperOrigin-RevId: 881959996 Change-Id: I67dbb7e9eab00bfef6b3db5ae414f81078f965bc --- .../common/rules/java_single_jar_tests.bzl | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index 8ea43da8..488aab3f 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -6,15 +6,6 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_single_jar.bzl", "java_single_jar") load("//java/common:java_semantics.bzl", "semantics") -def _label_to_bin_path(label): - segments = ["{bindir}"] - if label.repo_name: - segments.extend(["external", label.repo_name]) - segments.append(label.package) - return "/".join(segments) - -_BUILD_INFO_PATH = _label_to_bin_path(Label(semantics.BUILD_INFO_TRANSLATOR_LABEL)) - def _test_java_single_jar_basic(name): util.helper_target( java_single_jar, @@ -53,14 +44,17 @@ def _test_java_single_jar_force_enable_stamping(name): analysis_test( name = name, impl = _test_java_single_jar_force_enable_stamping_impl, - target = name + "/jar", + targets = { + "jar": name + "/jar", + "build_info": semantics.BUILD_INFO_TRANSLATOR_LABEL, + }, ) -def _test_java_single_jar_force_enable_stamping_impl(env, target): - assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") +def _test_java_single_jar_force_enable_stamping_impl(env, targets): + assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", _BUILD_INFO_PATH + "/non_volatile_file.properties"), - ("--build_info_file", _BUILD_INFO_PATH + "/volatile_file.properties"), + ("--build_info_file", f.path) + for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() ]) def _test_java_single_jar_force_disable_stamping(name): @@ -74,13 +68,17 @@ def _test_java_single_jar_force_disable_stamping(name): analysis_test( name = name, impl = _test_java_single_jar_force_disable_stamping_impl, - target = name + "/jar", + targets = { + "jar": name + "/jar", + "build_info": semantics.BUILD_INFO_TRANSLATOR_LABEL, + }, ) -def _test_java_single_jar_force_disable_stamping_impl(env, target): - assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") +def _test_java_single_jar_force_disable_stamping_impl(env, targets): + assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", _BUILD_INFO_PATH + "/redacted_file.properties"), + ("--build_info_file", f.path) + for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() ]) def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): @@ -114,17 +112,20 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl, - target = name + "/jar", + targets = { + "jar": name + "/jar", + "build_info": semantics.BUILD_INFO_TRANSLATOR_LABEL, + }, config_settings = { "//command_line_option:stamp": True, }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, target): - assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") +def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, targets): + assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", _BUILD_INFO_PATH + "/non_volatile_file.properties"), - ("--build_info_file", _BUILD_INFO_PATH + "/volatile_file.properties"), + ("--build_info_file", f.path) + for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() ]) def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): @@ -138,16 +139,20 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl, - target = name + "/jar", + targets = { + "jar": name + "/jar", + "build_info": semantics.BUILD_INFO_TRANSLATOR_LABEL, + }, config_settings = { "//command_line_option:stamp": False, }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, target): - assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") +def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets): + assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", _BUILD_INFO_PATH + "/redacted_file.properties"), + ("--build_info_file", f.path) + for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() ]) def java_single_jar_tests(name): From cc7a75a0d94972bf7c3cf659c13f3e3f43d8a942 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 11 Mar 2026 07:55:38 -0700 Subject: [PATCH 149/251] Implement java_test tests checking for compile time deps on the test runner. Updates rules_testing to include https://github.com/bazelbuild/rules_testing/commit/04a1219 PiperOrigin-RevId: 882013418 Change-Id: I077f6e957968e1b343765364866f24cae0cd3ad6 --- MODULE.bazel | 6 ++-- test/java/common/rules/java_test_tests.bzl | 40 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index e98ca3d1..769902b4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -124,9 +124,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-d/94Ix5IoGXk9rP1HjYKxPMH8ccwX5b1Qxs8BKg4WRg=", - strip_prefix = "rules_testing-ac97ba507116056cd489161b5e99dd8014685adc", - urls = ["https://github.com/bazelbuild/rules_testing/archive/ac97ba507116056cd489161b5e99dd8014685adc.tar.gz"], + integrity = "sha256-WYc72jM8jNK3m45vjWlmN6NB+95f6HAHnTkRaSaNisE=", + strip_prefix = "rules_testing-04a1219ee516ccdf3ffadfe3b28e5c634c9b90e1", + urls = ["https://github.com/bazelbuild/rules_testing/archive/04a1219ee516ccdf3ffadfe3b28e5c634c9b90e1.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 13362dc3..5c2001ca 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -8,6 +8,8 @@ load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") +load("//java/common:java_info.bzl", "JavaInfo") +load("//java/common:java_semantics.bzl", "semantics") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -228,6 +230,43 @@ def _test_stamp_values_impl(env, targets): env.expect.that_target(targets.defaultstamp).attr("stamp", factory = subjects.int).equals(0) env.expect.that_target(targets.autostamp).attr("stamp", factory = subjects.int).equals(-1) +def _test_add_test_support_to_compile_time_deps_flag(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + util.helper_target( + rule = java_test, + name = name + "/test", + srcs = [name + "/Test.java"], + ) + + analysis_test( + name = name, + targets = { + "add_support": name + "/test", + "no_add_support": name + "/test", + }, + attrs = { + "test_runner": attr.label(default = semantics.JAVA_TEST_RUNNER_LABEL), + "add_support": { + "@config_settings": { + "//command_line_option:experimental_add_test_support_to_compile_time_deps": True, + }, + }, + "no_add_support": { + "@config_settings": { + "//command_line_option:experimental_add_test_support_to_compile_time_deps": False, + }, + }, + }, + impl = _test_add_test_support_to_compile_time_deps_flag_impl, + ) + +def _test_add_test_support_to_compile_time_deps_flag_impl(env, targets): + compile_jars = env.ctx.attr.test_runner[JavaInfo].compile_jars + env.expect.that_target(targets.add_support).action_named("Javac").inputs().contains_at_least(compile_jars.to_list()) + env.expect.that_target(targets.no_add_support).action_named("Javac").inputs().contains_none_of(compile_jars.to_list()) + def java_test_tests(name): test_suite( name = name, @@ -238,5 +277,6 @@ def java_test_tests(name): _test_java_test_propagates_direct_native_libraries, _test_coverage_uses_coverage_runner_for_main, _test_stamp_values, + _test_add_test_support_to_compile_time_deps_flag, ], ) From 635d5aba4f5a5beb9f7a86712ad12968229de88a Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 12 Mar 2026 08:01:48 -0700 Subject: [PATCH 150/251] Implement darwin test in java_test. PiperOrigin-RevId: 882593123 Change-Id: I4285d4304e748935c6198d1e9cc98199eb3d200f --- java/common/java_semantics.bzl | 2 + test/java/common/rules/java_test_tests.bzl | 49 ++++++++++++++++ test/java/common/testutil/BUILD | 1 + .../common/testutil/mock_cc_toolchain.bzl | 56 +++++++++++++++++++ .../common/testutil/mock_test_toolchain.bzl | 29 ++++++++++ 5 files changed, 137 insertions(+) create mode 100644 test/java/common/testutil/BUILD create mode 100644 test/java/common/testutil/mock_cc_toolchain.bzl create mode 100644 test/java/common/testutil/mock_test_toolchain.bzl diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 31c0a006..58f957ef 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -105,6 +105,8 @@ semantics = struct( compatible_javac_options = _compatible_javac_options, LAUNCHER_FLAG_LABEL = Label("@bazel_tools//tools/jdk:launcher_flag_alias"), PROGUARD_ALLOWLISTER_LABEL = "@bazel_tools//tools/jdk:proguard_whitelister", + TOOLS_TEST_DEFAULT_TEST_TOOLCHAIN_TYPE = "@bazel_tools//tools/test:default_test_toolchain_type", + TOOLS_TEST_EMPTY_TOOLCHAIN = "@bazel_tools//tools/test:empty_toolchain", check_java_info_opens_exports = _check_java_info_opens_exports, DOCS = struct( for_attribute = lambda name: _DOCS.ATTRS.get(name, ""), diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 5c2001ca..bd8e6850 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -10,6 +10,8 @@ load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") +load("//test/java/common/testutil:mock_cc_toolchain.bzl", "mock_cc_toolchain") +load("//test/java/common/testutil:mock_test_toolchain.bzl", "mock_test_toolchains") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -267,6 +269,52 @@ def _test_add_test_support_to_compile_time_deps_flag_impl(env, targets): env.expect.that_target(targets.add_support).action_named("Javac").inputs().contains_at_least(compile_jars.to_list()) env.expect.that_target(targets.no_add_support).action_named("Javac").inputs().contains_none_of(compile_jars.to_list()) +def _test_mac_requires_darwin_for_execution(name): + util.helper_target( + rule = native.platform, + name = name + "/darwin_x86_64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + ) + + util.helper_target( + rule = java_test, + name = name + "/test", + srcs = [name + "/Test.java"], + use_launcher = False, + use_testrunner = 0, + ) + + util.helper_target( + rule = mock_cc_toolchain, + name = name + "/cc_toolchain", + cpu = "x86_64", + os = "macos", + ) + + toolchains = [Label(name + "/cc_toolchain")] + mock_test_toolchains( + name = name + "/test_toolchain", + cpu = "x86_64", + os = "macos", + ) + + analysis_test( + name = name, + target = name + "/test", + config_settings = { + "//command_line_option:platforms": [Label(name + "/darwin_x86_64")], + "//command_line_option:extra_toolchains": toolchains, + }, + impl = _test_mac_requires_darwin_for_execution_impl, + ) + +def _test_mac_requires_darwin_for_execution_impl(env, target): + env.expect.that_target(target).provider(testing.ExecutionInfo).requirements().contains_at_least( + {"requires-darwin": ""}, + ) + def java_test_tests(name): test_suite( name = name, @@ -278,5 +326,6 @@ def java_test_tests(name): _test_coverage_uses_coverage_runner_for_main, _test_stamp_values, _test_add_test_support_to_compile_time_deps_flag, + _test_mac_requires_darwin_for_execution, ], ) diff --git a/test/java/common/testutil/BUILD b/test/java/common/testutil/BUILD new file mode 100644 index 00000000..c2afbb31 --- /dev/null +++ b/test/java/common/testutil/BUILD @@ -0,0 +1 @@ +package(default_applicable_licenses = ["@rules_java//:license"]) diff --git a/test/java/common/testutil/mock_cc_toolchain.bzl b/test/java/common/testutil/mock_cc_toolchain.bzl new file mode 100644 index 00000000..6680938d --- /dev/null +++ b/test/java/common/testutil/mock_cc_toolchain.bzl @@ -0,0 +1,56 @@ +"""Fake cc_toolchain for testing arbitrary --platforms/--cpu""" + +load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_TYPE") +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain") +load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") + +def _mock_config_impl(ctx): + return [ + cc_common.create_cc_toolchain_config_info( + ctx = ctx, + toolchain_identifier = ctx.attr.id, + compiler = "nothing", + # These are deprecated but are mandatory parameters for older Bazel versions. + target_system_name = "deprecated_system_name", + target_cpu = "deprecated_cpu", + target_libc = "deprecated_libc", + ), + ] + +_mock_config = rule( + implementation = _mock_config_impl, + attrs = { + "id": attr.string(mandatory = True), + }, + provides = [CcToolchainConfigInfo], +) + +def mock_cc_toolchain(*, name, cpu, os, **kwargs): + _mock_config( + name = name + "_config", + id = cpu + "-" + os, + **kwargs + ) + cc_toolchain( + name = name + "_impl", + all_files = ":nothing", + as_files = ":nothing", + compiler_files = ":nothing", + dwp_files = ":nothing", + linker_files = ":nothing", + objcopy_files = ":nothing", + strip_files = ":nothing", + toolchain_config = name + "_config", + **kwargs + ) + native.toolchain( + name = name, + toolchain = name + "_impl", + toolchain_type = CC_TOOLCHAIN_TYPE, + target_compatible_with = [ + "@platforms//cpu:" + cpu, + "@platforms//os:" + os, + ], + **kwargs + ) diff --git a/test/java/common/testutil/mock_test_toolchain.bzl b/test/java/common/testutil/mock_test_toolchain.bzl new file mode 100644 index 00000000..cf73145e --- /dev/null +++ b/test/java/common/testutil/mock_test_toolchain.bzl @@ -0,0 +1,29 @@ +"""Fake test toolchain for testing arbitrary --platforms""" + +load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_testing//lib:util.bzl", "util") +load("//java/common:java_semantics.bzl", "semantics") + +def mock_test_toolchains(name, cpu, os): + """Creates and returns a list of mock test toolchains for the given cpu and os if they're required. + + Args: + name: The name of the toolchain. + cpu: The cpu for toolchain should be compatible with. + os: The os the toolchain should be compatible with. + Returns: + A list of toolchain targets. + """ + if not bazel_features.toolchains.has_default_test_toolchain_type: + return [] + util.helper_target( + rule = native.toolchain, + name = name, + toolchain_type = Label(semantics.TOOLS_TEST_DEFAULT_TEST_TOOLCHAIN_TYPE), + toolchain = Label(semantics.TOOLS_TEST_EMPTY_TOOLCHAIN), + target_compatible_with = [ + "@platforms//os:" + os, + "@platforms//cpu:" + cpu, + ], + ) + return [native.package_relative_label(name)] From 983b13c81d346abf8e3cd2d58200bd13b8668a77 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 13 Mar 2026 09:26:09 -0700 Subject: [PATCH 151/251] Implement applicable --java_launcher tests in Starlark and open-source them. PiperOrigin-RevId: 883202557 Change-Id: Ib83a9fa044eded610be4789e7868d351f7205720 --- test/java/common/rules/BUILD | 3 + .../java/common/rules/java_launcher_tests.bzl | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/java/common/rules/java_launcher_tests.bzl diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 8e74a2a0..28d38349 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -2,6 +2,7 @@ load(":add_exports_tests.bzl", "add_exports_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") +load(":java_launcher_tests.bzl", "java_launcher_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") load(":java_single_jar_tests.bzl", "java_single_jar_tests") @@ -20,6 +21,8 @@ java_plugin_tests(name = "java_plugin_tests") java_library_tests(name = "java_library_tests") +java_launcher_tests(name = "java_launcher_tests") + java_import_tests(name = "java_import_tests") java_single_jar_tests(name = "java_single_jar_tests") diff --git a/test/java/common/rules/java_launcher_tests.bzl b/test/java/common/rules/java_launcher_tests.bzl new file mode 100644 index 00000000..6faaa93f --- /dev/null +++ b/test/java/common/rules/java_launcher_tests.bzl @@ -0,0 +1,71 @@ +"""Tests for the "launcher" attribute and "--java_launcher" flag.""" + +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") + +def _test_overridden_incompatible_launcher(name): + # Check analysis succeeds even though --java_launcher refers to an incompatible target + # when the "use_launcher" attribute is set to False. + util.helper_target( + rule = cc_binary, + name = name + "/launcher", + srcs = select({ + "@platforms//cpu:ppc": [name + "/launcher.cc"], + }), + ) + + util.helper_target( + rule = java_binary, + name = name + "/bin", + srcs = [name + "/Bin.java"], + use_launcher = False, + ) + + analysis_test( + name = name, + impl = lambda env, target: True, + target = name + "/bin", + config_settings = { + "//command_line_option:java_launcher": Label(name + "/launcher"), + "//command_line_option:cpu": "k8", + }, + ) + +def _test_launcher_with_create_executable_false_fails(name): + util.helper_target( + rule = cc_binary, + name = name + "/launcher", + srcs = [name + "/launcher.cc"], + ) + + util.helper_target( + rule = java_binary, + name = name + "/bin", + srcs = [name + "/Bin.java"], + launcher = name + "/launcher", + create_executable = False, + ) + + analysis_test( + name = name, + impl = _test_launcher_with_create_executable_false_fails_impl, + target = name + "/bin", + expect_failure = True, + ) + +def _test_launcher_with_create_executable_false_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("launcher specified but create_executable is false"), + ) + +def java_launcher_tests(name): + test_suite( + name = name, + tests = [ + _test_overridden_incompatible_launcher, + _test_launcher_with_create_executable_false_fails, + ], + ) From 73bd40296fb7c529b79dbdbb2ce20f1cacaccda3 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 17 Mar 2026 05:40:03 -0700 Subject: [PATCH 152/251] Remove extra whitespace (ignore-relnotes) PiperOrigin-RevId: 884968144 Change-Id: I049060711f4c62930b5ff2c5cfa393966f99e92a --- java/common/rules/java_single_jar.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl index c9552755..ca768873 100644 --- a/java/common/rules/java_single_jar.bzl +++ b/java/common/rules/java_single_jar.bzl @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Definition of the java_single_jar rule.""" +"""Definition of the java_single_jar rule.""" load("//java/common:java_common.bzl", "java_common") load("//java/common:java_info.bzl", "JavaInfo") From f08336996aba472204a47dafb6bddb398f88c274 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 20 Mar 2026 02:41:19 -0700 Subject: [PATCH 153/251] Update `rules_java`'s `CODEOWNERS` (ignore-relnotes) PiperOrigin-RevId: 886664168 Change-Id: I7eb1ab776ae6ceadd619e1e460988943466fe637 --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 1f7a7ed6..9d182e13 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -14,4 +14,4 @@ # Component owners # ---------------- -* @comius @bazelbuild/java-team +* @hvadehra @bazelbuild/java-team From 22b3280dc0f2a2bf80024a280711bdaf8e9719c4 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 20 Mar 2026 12:14:47 -0700 Subject: [PATCH 154/251] Migrate `JavaStarlarkApiTest.testPackSourcesWithExternalResourceArtifact` to Starlark The test is removed from Bazel and added to `@rules_java` PiperOrigin-RevId: 886915767 Change-Id: Ibaacab7d5241e21a1a0b1870c335e20c88135a85 --- MODULE.bazel | 2 +- test/java/bazel/common/BUILD.bazel | 3 ++ test/java/bazel/common/java_common_tests.bzl | 41 ++++++++++++++++++++ test/repositories.bzl | 5 +++ test/testdata/other_repo/BUILD.bazel | 1 + test/testdata/other_repo/MODULE.bazel | 1 + 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/java/bazel/common/BUILD.bazel create mode 100644 test/java/bazel/common/java_common_tests.bzl create mode 100644 test/testdata/other_repo/BUILD.bazel create mode 100644 test/testdata/other_repo/MODULE.bazel diff --git a/MODULE.bazel b/MODULE.bazel index 769902b4..38405ca6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -130,4 +130,4 @@ archive_override( ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) -use_repo(test_repositories, "guava", "truth") +use_repo(test_repositories, "guava", "other_repo", "truth") diff --git a/test/java/bazel/common/BUILD.bazel b/test/java/bazel/common/BUILD.bazel new file mode 100644 index 00000000..18ab4f84 --- /dev/null +++ b/test/java/bazel/common/BUILD.bazel @@ -0,0 +1,3 @@ +load(":java_common_tests.bzl", "java_common_tests") + +java_common_tests(name = "java_common_tests") diff --git a/test/java/bazel/common/java_common_tests.bzl b/test/java/bazel/common/java_common_tests.bzl new file mode 100644 index 00000000..80fdf442 --- /dev/null +++ b/test/java/bazel/common/java_common_tests.bzl @@ -0,0 +1,41 @@ +"""Bazel tests for java_common APIs""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") + +def _test_java_common_pack_sources_with_external_resource(name): + util.helper_target( + custom_java_info_rule, + name = name + "/custom", + output_jar = name + "/custom.jar", + sources = [ + ":InternalLib.java", + "@other_repo//:ExternalLib.java", + ], + pack_sources = True, + ) + + analysis_test( + name = name, + impl = _test_java_common_pack_sources_with_external_resource_impl, + target = name + "/custom", + # Bazel 7 names external repos differently + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_common_pack_sources_with_external_resource_impl(env, target): + assert_that_action = env.expect.that_target(target).action_generating("{package}/{name}-src.jar") + assert_that_action.argv().contains_at_least([ + "--resources", + "{package}/InternalLib.java:bazel/common/InternalLib.java", + "external/+test_repositories_ext+other_repo/ExternalLib.java:ExternalLib.java", + ]).in_order() + +def java_common_tests(name): + test_suite( + name = name, + tests = [ + _test_java_common_pack_sources_with_external_resource, + ], + ) diff --git a/test/repositories.bzl b/test/repositories.bzl index 5d4f568d..0f0afd53 100644 --- a/test/repositories.bzl +++ b/test/repositories.bzl @@ -5,6 +5,7 @@ load("@bazel_skylib//lib:modules.bzl", "modules") # TODO: Use http_jar from //java:http_jar.bzl once it doesn't refert to cache.bzl from @bazel_tools # anymore, which isn't available in Bazel 6. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") def test_repositories(): http_file( @@ -19,5 +20,9 @@ def test_repositories(): integrity = "sha256-Ushs3a3DG8hFfB4VaJ/Gt14ul84qg9i1S3ldVW1In4w=", downloaded_file_path = "truth.jar", ) + local_repository( + name = "other_repo", + path = "test/testdata/other_repo", + ) test_repositories_ext = modules.as_extension(test_repositories) diff --git a/test/testdata/other_repo/BUILD.bazel b/test/testdata/other_repo/BUILD.bazel new file mode 100644 index 00000000..fc25d5fb --- /dev/null +++ b/test/testdata/other_repo/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["ExternalLib.java"]) diff --git a/test/testdata/other_repo/MODULE.bazel b/test/testdata/other_repo/MODULE.bazel new file mode 100644 index 00000000..f90d195a --- /dev/null +++ b/test/testdata/other_repo/MODULE.bazel @@ -0,0 +1 @@ +module(name = "other_repo") From 8c82b7f5677a3f2427cbd10b23e3902735b1d03f Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 23 Mar 2026 14:33:05 -0700 Subject: [PATCH 155/251] No public description PiperOrigin-RevId: 888283852 Change-Id: Id71e2bb5fcfab1c6469dbcdc067d0f65f3d2cdec --- java/common/rules/impl/basic_java_library_impl.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/common/rules/impl/basic_java_library_impl.bzl b/java/common/rules/impl/basic_java_library_impl.bzl index a0105794..affd222f 100644 --- a/java/common/rules/impl/basic_java_library_impl.bzl +++ b/java/common/rules/impl/basic_java_library_impl.bzl @@ -160,7 +160,8 @@ def basic_java_library( validation_outputs = [] - if ctx.fragments.java.run_android_lint: + # Validation actions don't run in the exec config, so no need to create them. + if ctx.fragments.java.run_android_lint and not ctx.configuration.is_tool_configuration(): generated_source_jars = [ output.generated_source_jar for output in java_info.java_outputs From db20055480ba2c0ac85a923b3e68e18cb872dfa5 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 24 Mar 2026 08:14:39 -0700 Subject: [PATCH 156/251] Move mock toolchain files to `test/java/testutil` PiperOrigin-RevId: 888674071 Change-Id: I99783a86f6e3ffb137d1bcdbba00b2a14ce70294 --- test/java/common/rules/java_test_tests.bzl | 4 ++-- test/java/common/testutil/BUILD | 1 - test/java/{common => }/testutil/mock_cc_toolchain.bzl | 0 test/java/{common => }/testutil/mock_test_toolchain.bzl | 0 4 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 test/java/common/testutil/BUILD rename test/java/{common => }/testutil/mock_cc_toolchain.bzl (100%) rename test/java/{common => }/testutil/mock_test_toolchain.bzl (100%) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index bd8e6850..f1c44662 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -10,9 +10,9 @@ load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") -load("//test/java/common/testutil:mock_cc_toolchain.bzl", "mock_cc_toolchain") -load("//test/java/common/testutil:mock_test_toolchain.bzl", "mock_test_toolchains") load("//test/java/testutil:helper.bzl", "always_passes") +load("//test/java/testutil:mock_cc_toolchain.bzl", "mock_cc_toolchain") +load("//test/java/testutil:mock_test_toolchain.bzl", "mock_test_toolchains") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") def _test_java_test_is_test_only(name): diff --git a/test/java/common/testutil/BUILD b/test/java/common/testutil/BUILD deleted file mode 100644 index c2afbb31..00000000 --- a/test/java/common/testutil/BUILD +++ /dev/null @@ -1 +0,0 @@ -package(default_applicable_licenses = ["@rules_java//:license"]) diff --git a/test/java/common/testutil/mock_cc_toolchain.bzl b/test/java/testutil/mock_cc_toolchain.bzl similarity index 100% rename from test/java/common/testutil/mock_cc_toolchain.bzl rename to test/java/testutil/mock_cc_toolchain.bzl diff --git a/test/java/common/testutil/mock_test_toolchain.bzl b/test/java/testutil/mock_test_toolchain.bzl similarity index 100% rename from test/java/common/testutil/mock_test_toolchain.bzl rename to test/java/testutil/mock_test_toolchain.bzl From afefe1efcadb8ba65a9772b8b5dadbf5595ebfa1 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 25 Mar 2026 00:57:51 -0700 Subject: [PATCH 157/251] Deduplicate mock `java_toolchain` declarations Additionally: - Minimize the definitions and explicitly set the arguments asserted on in the test cases - Where possible, switch from asserting on the java_toolchain target explicitly and use the resolved toolchain via `java_toolchain_alias` (ignore-relnotes) PiperOrigin-RevId: 889084161 Change-Id: Ia89dac8f5ed9ed81f5366e3df3cb6d75aa4a310b --- .../rules/deploy_archive_builder_tests.bzl | 51 +--- test/java/testutil/mock_java_toolchain.bzl | 62 ++++ test/java/toolchains/java_runtime_tests.bzl | 32 +-- test/java/toolchains/java_toolchain_tests.bzl | 264 +++++++++++------- 4 files changed, 238 insertions(+), 171 deletions(-) create mode 100644 test/java/testutil/mock_java_toolchain.bzl diff --git a/test/java/common/rules/deploy_archive_builder_tests.bzl b/test/java/common/rules/deploy_archive_builder_tests.bzl index 32e75e91..727790f8 100644 --- a/test/java/common/rules/deploy_archive_builder_tests.bzl +++ b/test/java/common/rules/deploy_archive_builder_tests.bzl @@ -4,58 +4,13 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") -load("//java/common:java_semantics.bzl", "semantics") -load("//java/toolchains:java_runtime.bzl", "java_runtime") -load("//java/toolchains:java_toolchain.bzl", "java_toolchain") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") -def _declare_java_toolchain(*, name, **kwargs): - java_runtime_name = name + "/runtime" - util.helper_target( - java_runtime, - name = java_runtime_name, - ) - toolchain_attrs = { - "source_version": "6", - "target_version": "6", - "bootclasspath": ["rt.jar"], - "xlint": ["toto"], - "javacopts": ["-Xmaxerrs 500"], - "compatible_javacopts": { - "android": ["-XDandroidCompatible"], - "testonly": ["-XDtestOnly"], - "public_visibility": ["-XDpublicVisibility"], - }, - "tools": [":javac_canary.jar"], - "javabuilder": ":JavaBuilder_deploy.jar", - "header_compiler": ":turbine_canary_deploy.jar", - "header_compiler_direct": ":turbine_direct", - "singlejar": "singlejar", - "ijar": "ijar", - "genclass": "GenClass_deploy.jar", - "timezone_data": "tzdata.jar", - "header_compiler_builtin_processors": ["BuiltinProc1", "BuiltinProc2"], - "reduced_classpath_incompatible_processors": [ - "IncompatibleProc1", - "IncompatibleProc2", - ], - "java_runtime": java_runtime_name, - } - toolchain_attrs.update(kwargs) - util.helper_target( - java_toolchain, - name = name + "/java_toolchain", - **toolchain_attrs - ) +def _test_custom_singlejar(name): util.helper_target( - native.toolchain, + mock_java_toolchain, name = name + "/toolchain", - toolchain = name + "/java_toolchain", - toolchain_type = semantics.JAVA_TOOLCHAIN_TYPE, ) - -def _test_custom_singlejar(name): - _declare_java_toolchain(name = name) - util.helper_target( java_binary, name = name + "/binary", diff --git a/test/java/testutil/mock_java_toolchain.bzl b/test/java/testutil/mock_java_toolchain.bzl new file mode 100644 index 00000000..c0ca6317 --- /dev/null +++ b/test/java/testutil/mock_java_toolchain.bzl @@ -0,0 +1,62 @@ +"""Fake java toolchains for testing""" + +load("//java/common:java_semantics.bzl", "semantics") +load("//java/toolchains:java_runtime.bzl", _java_runtime_rule = "java_runtime") +load("//java/toolchains:java_toolchain.bzl", "java_toolchain") + +# buildifier: disable=function-docstring +def mock_java_toolchain( + *, + name, + singlejar = "singlejar", + javabuilder = "JavaBuilder_deploy.jar", + header_compiler = "turbine_canary_deploy.jar", + header_compiler_direct = "turbine_direct", + ijar = "ijar", + genclass = "genclass", + java_runtime = None, + tags = None, # for util.helper_target + **kwargs): + if not java_runtime: + java_runtime = name + "_runtime" + _java_runtime_rule(name = java_runtime) + java_toolchain( + name = name + "_java", + javabuilder = javabuilder, + singlejar = singlejar, + header_compiler = header_compiler, + header_compiler_direct = header_compiler_direct, + ijar = ijar, + java_runtime = java_runtime, + genclass = genclass, + tags = tags, + **kwargs + ) + native.toolchain( + name = name, + toolchain = name + "_java", + toolchain_type = semantics.JAVA_TOOLCHAIN_TYPE, + tags = tags, + ) + +# buildifier: disable=function-docstring +def mock_java_runtime_toolchain( + *, + name, + srcs = [], + java_home = None, + java = None, + **kwargs): + _java_runtime_rule( + name = name + "_runtime", + srcs = srcs, + java_home = java_home, + java = java, + **kwargs + ) + native.toolchain( + name = name, + toolchain = name + "_runtime", + toolchain_type = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE, + **kwargs + ) diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 0112b172..94d067ea 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl @@ -4,16 +4,16 @@ load("@rules_cc//cc:defs.bzl", "cc_import") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") -load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") load("//test/java/testutil:java_runtime_info_subject.bzl", "java_runtime_info_subject") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_runtime_toolchain") load("//test/java/testutil:rules/forward_java_runtime_info.bzl", "java_runtime_info_forwarding_rule") load("//toolchains:java_toolchain_alias.bzl", "java_runtime_alias") def _test_with_absolute_java_home(name): util.helper_target( - java_runtime, - name = name + "/jvm", + mock_java_runtime_toolchain, + name = name + "/java_runtime_toolchain", srcs = [], java_home = "/foo/bar", ) @@ -26,12 +26,6 @@ def _test_with_absolute_java_home(name): name = name + "/r", java_runtime = name + "/alias", ) - util.helper_target( - native.toolchain, - name = name + "/java_runtime_toolchain", - toolchain = name + "/jvm", - toolchain_type = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE, - ) analysis_test( name = name, @@ -52,8 +46,8 @@ def _test_with_absolute_java_home_impl(env, target): def _test_with_hermetic_java_home(name): util.helper_target( - java_runtime, - name = name + "/jvm", + mock_java_runtime_toolchain, + name = name + "/java_runtime_toolchain", srcs = [], java_home = "foo/bar", ) @@ -66,12 +60,6 @@ def _test_with_hermetic_java_home(name): name = name + "/r", java_runtime = name + "/alias", ) - util.helper_target( - native.toolchain, - name = name + "/java_runtime_toolchain", - toolchain = name + "/jvm", - toolchain_type = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE, - ) analysis_test( name = name, @@ -99,8 +87,8 @@ def _test_with_generated_java_executable(name): output_to_bindir = True, ) util.helper_target( - java_runtime, - name = name + "/jvm", + mock_java_runtime_toolchain, + name = name + "/java_runtime_toolchain", srcs = [], java = "foo/bar/bin/java", ) @@ -113,12 +101,6 @@ def _test_with_generated_java_executable(name): name = name + "/r", java_runtime = name + "/alias", ) - util.helper_target( - native.toolchain, - name = name + "/java_runtime_toolchain", - toolchain = name + "/jvm", - toolchain_type = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE, - ) analysis_test( name = name, diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 372b9995..793de8ea 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -7,58 +7,24 @@ load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_common.bzl", "java_common") -load("//java/common:java_semantics.bzl", "semantics") -load("//java/toolchains:java_runtime.bzl", "java_runtime") -load("//java/toolchains:java_toolchain.bzl", "java_toolchain") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:java_toolchain_info_subject.bzl", "java_toolchain_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") load("//toolchains:java_toolchain_alias.bzl", "java_toolchain_alias") -def _declare_java_toolchain(*, name, **kwargs): - java_runtime_name = name + "/runtime" - java_runtime(name = java_runtime_name) - toolchain_attrs = { - "source_version": "6", - "target_version": "6", - "bootclasspath": ["rt.jar"], - "xlint": ["toto"], - "javacopts": ["-Xmaxerrs 500"], - "compatible_javacopts": { - "android": ["-XDandroidCompatible"], - "testonly": ["-XDtestOnly"], - "public_visibility": ["-XDpublicVisibility"], - }, - "tools": [":javac_canary.jar"], - "javabuilder": ":JavaBuilder_deploy.jar", - "header_compiler": ":turbine_canary_deploy.jar", - "header_compiler_direct": ":turbine_direct", - "singlejar": "singlejar", - "ijar": "ijar", - "genclass": "GenClass_deploy.jar", - "timezone_data": "tzdata.jar", - "header_compiler_builtin_processors": ["BuiltinProc1", "BuiltinProc2"], - "reduced_classpath_incompatible_processors": [ - "IncompatibleProc1", - "IncompatibleProc2", - ], - "java_runtime": java_runtime_name, - } - toolchain_attrs.update(kwargs) - util.helper_target( - java_toolchain, - name = name + "/java_toolchain", - **toolchain_attrs - ) +def _test_javac_gets_options(name): util.helper_target( - native.toolchain, + mock_java_toolchain, name = name + "/toolchain", - toolchain = name + "/java_toolchain", - toolchain_type = semantics.JAVA_TOOLCHAIN_TYPE, + javabuilder = name + "/JavaBuilder_deploy.jar", + header_compiler_direct = name + "/turbine_direct", + bootclasspath = [name + "/rt.jar"], + source_version = "6", + target_version = "6", + xlint = ["toto"], + javacopts = ["-Xmaxerrs 500"], ) - -def _test_javac_gets_options(name): - _declare_java_toolchain(name = name) util.helper_target( java_library, name = name + "/b", @@ -95,24 +61,31 @@ def _test_javac_gets_options_impl(env, targets): "-Xmaxerrs", "500", ]) - assert_javac_action.jar().contains_exactly(["{package}/JavaBuilder_deploy.jar"]) - assert_javac_action.inputs().contains("{package}/rt.jar") + assert_javac_action.jar().contains_exactly(["{package}/{test_name}/JavaBuilder_deploy.jar"]) + assert_javac_action.inputs().contains("{package}/{test_name}/rt.jar") assert_javac_action.javacopts().not_contains("-g") assert_header_action = javac_action_subject.of(env, targets.b, "{package}/lib{name}-hjar.jar") - assert_header_action.argv().contains("{package}/turbine_direct") + assert_header_action.argv().contains("{package}/{test_name}/turbine_direct") def _test_jacocorunner(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", jacocorunner = "myjacocorunner.jar", ) - + util.helper_target( + java_toolchain_alias, + name = name + "/alias", + ) analysis_test( name = name, impl = _test_jacocorunner_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_jacocorunner_impl(env, target): @@ -121,7 +94,10 @@ def _test_jacocorunner_impl(env, target): assert_toolchain.jacocorunner().short_path_equals("{package}/myjacocorunner.jar") def _test_singlejar_get_command_line(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + ) util.helper_target( java_binary, name = name + "/a", @@ -144,7 +120,11 @@ def _test_singlejar_get_command_line_impl(env, target): assert_javac_action.executable_file_name().equals(target.label.package + "/singlejar") def _test_genclass_get_command_line(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + genclass = name + "/GenClass_deploy.jar", + ) util.helper_target( java_library, name = name + "/a", @@ -164,15 +144,26 @@ def _test_genclass_get_command_line(name): def _test_genclass_get_command_line_impl(env, target): assert_javac_action = javac_action_subject.of(env, target, "{package}/lib{name}-gen.jar") - assert_javac_action.jar().contains_exactly(["{package}/GenClass_deploy.jar"]) + assert_javac_action.jar().contains_exactly(["{package}/{test_name}/GenClass_deploy.jar"]) def _test_timezone_data_is_correct(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + timezone_data = "tzdata.jar", + ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", + ) analysis_test( name = name, impl = _test_timezone_data_is_correct_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_timezone_data_is_correct_impl(env, target): @@ -181,7 +172,11 @@ def _test_timezone_data_is_correct_impl(env, target): ) def _test_java_binary_uses_timezone_data(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + timezone_data = name + "/tzdata.jar", + ) util.helper_target( java_binary, name = name + "/a", @@ -199,11 +194,14 @@ def _test_java_binary_uses_timezone_data(name): def _test_java_binary_uses_timezone_data_impl(env, target): assert_action = javac_action_subject.of(env, target, "{package}/{name}.jar") - assert_action.sources().contains("{package}/tzdata.jar") + assert_action.sources().contains("{package}/{test_name}/tzdata.jar") assert_action.inputs().contains_predicate(matching.file_basename_equals("tzdata.jar")) def _test_ijar_get_command_line(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + ) util.helper_target( java_library, name = name + "/a", @@ -227,8 +225,9 @@ def _test_ijar_get_command_line_impl(env, target): ) def _test_no_header_compiler_header_compilation_enabled_fails(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", header_compiler = None, ) util.helper_target( @@ -255,8 +254,9 @@ def _test_no_header_compiler_header_compilation_enabled_fails_impl(env, target): ) def _test_no_header_compiler_direct_header_compilation_enabled_fails(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", header_compiler_direct = None, ) util.helper_target( @@ -283,8 +283,9 @@ def _test_no_header_compiler_direct_header_compilation_enabled_fails_impl(env, t ) def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", header_compiler = None, ) util.helper_target( @@ -311,41 +312,60 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_i def _test_header_compiler_builtin_processors(name): util.helper_target( - java_toolchain, - name = name + "/java_toolchain", + mock_java_toolchain, + name = name + "/toolchain", header_compiler_builtin_processors = ["BuiltinProc1", "BuiltinProc2"], - singlejar = "singlejar", + ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", ) analysis_test( name = name, impl = _test_header_compiler_builtin_processors_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_header_compiler_builtin_processors_impl(env, target): - java_toolchain_info_subject.from_target(env, target).header_compiler_builtin_processors().contains_exactly(["BuiltinProc1", "BuiltinProc2"]) + java_toolchain_info_subject.from_target(env, target).header_compiler_builtin_processors().contains_exactly([ + "BuiltinProc1", + "BuiltinProc2", + ]) def _test_reduced_classpath_incompatible_processors(name): util.helper_target( - java_toolchain, - name = name + "/java_toolchain", + mock_java_toolchain, + name = name + "/toolchain", reduced_classpath_incompatible_processors = ["IncompatibleProc1", "IncompatibleProc2"], - singlejar = "singlejar", + ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", ) analysis_test( name = name, impl = _test_reduced_classpath_incompatible_processors_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_reduced_classpath_incompatible_processors_impl(env, target): - java_toolchain_info_subject.from_target(env, target).reduced_classpath_incompatible_processors().contains_exactly(["IncompatibleProc1", "IncompatibleProc2"]) + java_toolchain_info_subject.from_target(env, target).reduced_classpath_incompatible_processors().contains_exactly([ + "IncompatibleProc1", + "IncompatibleProc2", + ]) def _test_location_expansion_in_jvm_opts(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", tools = [name + "/jsr305.jar", name + "/javac"], jvm_opts = [ "--patch-module=jdk.compiler=$(location " + name + "/javac)", @@ -381,8 +401,9 @@ def _test_location_expansion_with_multiple_artifacts_fails(name): name = name + "/fg", srcs = ["one", "two"], ) - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", tools = [name + "/fg"], javabuilder_jvm_opts = ["$(location " + name + "/fg)"], ) @@ -390,7 +411,7 @@ def _test_location_expansion_with_multiple_artifacts_fails(name): analysis_test( name = name, impl = _test_location_expansion_with_multiple_artifacts_fails_impl, - target = name + "/java_toolchain", + target = name + "/toolchain_java", # the underlying java_toolchain expect_failure = True, ) @@ -405,15 +426,16 @@ def _test_timezone_data_with_multiple_artifacts_fails(name): name = name + "/fg", srcs = ["one", "two"], ) - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", timezone_data = name + "/fg", ) analysis_test( name = name, impl = _test_timezone_data_with_multiple_artifacts_fails_impl, - target = name + "/java_toolchain", + target = name + "/toolchain_java", # the underlying java_toolchain expect_failure = True, ) @@ -423,8 +445,12 @@ def _test_timezone_data_with_multiple_artifacts_fails_impl(env, target): ) def _test_java_compile_action_target_gets_javacopts_from_toolchain(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + source_version = "6", + target_version = "6", + xlint = ["toto"], javacopts = ["-XDtoolchainJavacFlag"], ) util.helper_target( @@ -456,8 +482,12 @@ def _test_java_compile_action_target_gets_javacopts_from_toolchain_impl(env, tar ]) def _test_java_compile_action_exec_gets_javacopts_from_toolchain(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + source_version = "6", + target_version = "6", + xlint = ["toto"], javacopts = ["-XDtoolchainJavacFlag"], ) util.helper_target( @@ -495,8 +525,9 @@ def _test_java_compile_action_exec_gets_javacopts_from_toolchain_impl(env, targe ]) def _test_java_compile_action_uses_tool_specific_jvm_opts(name): - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", jvm_opts = ["-Xbase"], javabuilder_jvm_opts = ["-DjavabuilderFlag=1"], turbine_jvm_opts = ["-DturbineFlag=1"], @@ -540,19 +571,27 @@ def _test_javabuilder_location_expansion_with_multiple_artifacts(name): name = name + "/fg2", srcs = ["c", "d"], ) - _declare_java_toolchain( - name = name, + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", javabuilder_data = [name + "/fg1", name + "/fg2"], javabuilder_jvm_opts = [ "$(locations " + name + "/fg1)", "$(locations " + name + "/fg2)", ], ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", + ) analysis_test( name = name, impl = _test_javabuilder_location_expansion_with_multiple_artifacts_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_javabuilder_location_expansion_with_multiple_artifacts_impl(env, target): @@ -621,7 +660,10 @@ def _test_java_toolchain_flag_default_impl(env, target): ) def _test_java_toolchain_flag_set(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + ) util.helper_target( java_toolchain_alias, name = name + "/toolchain_alias", @@ -632,7 +674,7 @@ def _test_java_toolchain_flag_set(name): impl = _test_java_toolchain_flag_set_impl, targets = { "alias": name + "/toolchain_alias", - "toolchain": name + "/java_toolchain", + "toolchain": name + "/toolchain_java", # the underlying java_toolchain }, config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], @@ -644,13 +686,27 @@ def _test_java_toolchain_flag_set_impl(env, targets): assert_toolchain.label().equals(targets.toolchain.label) def _test_default_javac_opts_depset(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + source_version = "6", + target_version = "6", + xlint = ["toto"], + javacopts = ["-Xmaxerrs 500"], + ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", + ) analysis_test( name = name, impl = _test_default_javac_opts_depset_impl, - target = name + "/java_toolchain", + target = name + "/alias", attr_values = {"tags": ["min_bazel_8"]}, + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, ) def _test_default_javac_opts_depset_impl(env, target): @@ -659,12 +715,24 @@ def _test_default_javac_opts_depset_impl(env, target): ) def _test_default_javac_opts(name): - _declare_java_toolchain(name = name) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + source_version = "6", + target_version = "6", + ) + util.helper_target( + java_toolchain_alias, + name = name + "/alias", + ) analysis_test( name = name, impl = _test_default_javac_opts_impl, - target = name + "/java_toolchain", + target = name + "/alias", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, attr_values = {"tags": ["min_bazel_8"]}, ) From 5ae9e83b1e3c771a0f79dbe8d157f65a4f20451e Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 26 Mar 2026 03:34:35 -0700 Subject: [PATCH 158/251] Internal change (ignore-relnotes) PiperOrigin-RevId: 889735173 Change-Id: Ia6d4adaf419af786f5ad842948a509ddfb7c9232 --- java/common/rules/java_package_configuration.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/common/rules/java_package_configuration.bzl b/java/common/rules/java_package_configuration.bzl index e6b1885f..a1abcd05 100644 --- a/java/common/rules/java_package_configuration.bzl +++ b/java/common/rules/java_package_configuration.bzl @@ -18,7 +18,7 @@ load("//java/common/rules:java_helper.bzl", "helper") load("//java/private:boot_class_path_info.bzl", "BootClassPathInfo") load("//java/private:native.bzl", "get_internal_java_common") -# copybara: default visibility +# copybara: rules_java visibility JavaPackageConfigurationInfo = provider( "A provider for Java per-package configuration", From 747bddd6091a624c54a42c1ac20308190c1ad849 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 1 Apr 2026 13:34:36 -0700 Subject: [PATCH 159/251] Add `java_library` tests (ignore-relnotes) PiperOrigin-RevId: 893090207 Change-Id: Idc90df60767576cf47d3e9faba36465da7534818 --- .../common_launcher_java_library_tests.bzl | 226 ++++++++++++++++++ test/java/testutil/javac_action_subject.bzl | 1 + 2 files changed, 227 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index 8f0ed228..9690b2ba 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -1,8 +1,13 @@ """Parameterized tests for java_library with --java_launcher""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:util.bzl", "util") +load("//java:java_import.bzl", "java_import") load("//java:java_library.bzl", "java_library") +load("//test/java/testutil:helper.bzl", "always_passes") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") def _test_java_library_rule_outputs(name): util.helper_target( @@ -22,6 +27,227 @@ def _test_java_library_rule_outputs_impl(env, target): "{package}/lib{name}.jar", ]) +def _test_java_library_action_graph(name): + util.helper_target( + java_library, + name = name + "/test_lib", + srcs = [ + "Util.java", + "Util2.java", + ], + javacopts = [ + "-g", + "-encoding", + "utf8", + ], + ) + + analysis_test( + name = name, + impl = _test_java_library_action_graph_impl, + target = name + "/test_lib", + ) + +def _test_java_library_action_graph_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.inputs().contains_at_least([ + "{package}/Util.java", + "{package}/Util2.java", + ]) + javac_action.javacopts().contains_at_least([ + "-g", + "-encoding", + "utf8", + ]) + +def _test_java_library_deps_of_genrule_are_not_on_classpath(name): + util.helper_target( + java_library, + name = name + "/root_dep", + srcs = ["test.java"], + ) + util.helper_target( + native.genrule, + name = name + "/has_java_dep", + outs = ["foo.jar"], + cmd = "echo NOT EXECUTED", + tools = [name + "/root_dep"], + ) + util.helper_target( + java_import, + name = name + "/has_java_dep_import", + jars = [name + "/has_java_dep"], + ) + util.helper_target( + java_library, + name = name + "/library", + srcs = ["dummy.java"], + deps = [name + "/has_java_dep_import"], + ) + + analysis_test( + name = name, + impl = _test_java_library_deps_of_genrule_are_not_on_classpath_impl, + target = name + "/library", + ) + +def _test_java_library_deps_of_genrule_are_not_on_classpath_impl(env, target): + expected_classpath = "{bin_path}/{package}/_ijar/{test_name}/has_java_dep_import/{package}/foo-ijar.jar" + javac_action_subject.of(env, target, "{package}/lib{name}.jar").classpath().contains_exactly([expected_classpath]) + +def _test_java_library_compile_and_run_time_paths(name): + util.helper_target( + java_library, + name = name + "/base", + srcs = ["Base.java"], + ) + util.helper_target( + java_library, + name = name + "/specialization", + srcs = ["Specialization.java"], + deps = [name + "/base"], + ) + + analysis_test( + name = name, + impl = _test_java_library_compile_and_run_time_paths_impl, + targets = { + "base": name + "/base", + "specialization": name + "/specialization", + }, + ) + +def _test_java_library_compile_and_run_time_paths_impl(env, targets): + base_info = java_info_subject.from_target(env, targets.base) + base_info.compilation_args().transitive_runtime_jars().contains_exactly(["{package}/lib{name}.jar"]) + base_info.compilation_args().transitive_compile_time_jars().contains_exactly(["{package}/lib{name}-hjar.jar"]) + base_info.compilation_args().compile_jars().contains_exactly(["{package}/lib{name}-hjar.jar"]) + + base_jar = "{package}/lib{test_name}/base.jar" + base_hjar = "{package}/lib{test_name}/base-hjar.jar" + + specialization_info = java_info_subject.from_target(env, targets.specialization) + specialization_info.compilation_args().transitive_runtime_jars().contains_exactly([ + base_jar, + "{package}/lib{name}.jar", + ]) + specialization_info.compilation_args().transitive_compile_time_jars().contains_exactly([ + base_hjar, + "{package}/lib{name}-hjar.jar", + ]) + specialization_info.compilation_args().compile_jars().contains_exactly(["{package}/lib{name}-hjar.jar"]) + +def _test_java_library_files_to_compile(name): + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Lib.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_files_to_compile_impl, + target = name + "/lib", + ) + +def _test_java_library_files_to_compile_impl(env, target): + env.expect.that_target(target).output_group("compilation_outputs").contains_exactly(["{package}/lib{name}.jar"]) + +def _test_java_library_runtime_deps_are_not_on_classpath(name): + util.helper_target( + java_library, + name = name + "/runtime_java_dep", + srcs = ["test.java"], + ) + util.helper_target( + java_library, + name = name + "/compile_dep", + srcs = ["compile.java"], + ) + util.helper_target( + java_library, + name = name + "/depends_on_runtimedep", + srcs = ["dummy.java"], + runtime_deps = [name + "/runtime_java_dep"], + deps = [name + "/compile_dep"], + ) + + analysis_test( + name = name, + impl = _test_java_library_runtime_deps_are_not_on_classpath_impl, + target = name + "/depends_on_runtimedep", + ) + +def _test_java_library_runtime_deps_are_not_on_classpath_impl(env, target): + expected_compile = "{bin_path}/{package}/lib{test_name}/compile_dep-hjar.jar" + javac_action_subject.of(env, target, "{package}/lib{name}.jar").classpath().contains_exactly([expected_compile]) + +def _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation(name): + util.helper_target( + java_library, + name = name + "/runtime_java_dep", + srcs = ["test.java"], + ) + util.helper_target( + java_library, + name = name + "/compile_dep", + srcs = ["compile.java"], + ) + util.helper_target( + java_library, + name = name + "/depends_on_runtimedep", + srcs = ["dummy.java"], + runtime_deps = [name + "/runtime_java_dep"], + deps = [name + "/compile_dep"], + ) + + analysis_test( + name = name, + impl = _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation_impl, + config_settings = { + "//command_line_option:java_header_compilation": True, + }, + target = name + "/depends_on_runtimedep", + ) + +def _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation_impl(env, target): + expected_compile = "{bin_path}/{package}/lib{test_name}/compile_dep-hjar.jar" + javac_action_subject.of(env, target, "{package}/lib{name}.jar").classpath().contains_exactly([expected_compile]) + +def _test_java_library_fix_deps_tool_written_to_params_file(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # Bazel 7 does not support transition on experimental_* flags. + # Exit early because this test case would be a loading phase error otherwise. + always_passes(name) + return + util.helper_target( + java_library, + name = name + "/base", + srcs = ["Base.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_fix_deps_tool_written_to_params_file_impl, + config_settings = { + "//command_line_option:experimental_fix_deps_tool": "fixer", + }, + target = name + "/base", + ) + +def _test_java_library_fix_deps_tool_written_to_params_file_impl(env, target): + javac_action_subject.of(env, target, "{package}/lib{name}.jar").argv().contains_at_least([ + "--experimental_fix_deps_tool", + "fixer", + ]).in_order() + JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_rule_outputs, + _test_java_library_action_graph, + _test_java_library_deps_of_genrule_are_not_on_classpath, + _test_java_library_compile_and_run_time_paths, + _test_java_library_files_to_compile, + _test_java_library_runtime_deps_are_not_on_classpath, + _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation, + _test_java_library_fix_deps_tool_written_to_params_file, ] diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index beb0ecbc..057040b0 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -25,6 +25,7 @@ def _new_javac_action_subject(env, target, output): # An unset --strict_java_deps is equivalent to "OFF". strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), + classpath = lambda: _create_subject_for_flag("--classpath", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, argv = action_subject.argv, From 23998995830e7ac87f2d6d7f3f17a8dade05ea23 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 15 Apr 2026 05:48:09 -0700 Subject: [PATCH 160/251] Internal change PiperOrigin-RevId: 900117275 Change-Id: I258daa1e7ddd4eddd69041b8f1a78eeb78de8f20 --- java/common/java_semantics.bzl | 6 ++++++ java/private/java_info.bzl | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 58f957ef..3a7459ca 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Bazel Java Semantics""" +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper") # copybara: default visibility @@ -41,6 +42,10 @@ def _check_java_info_opens_exports(): def _minimize_cc_info(cc_info): return cc_info +def _merge_cc_infos(*args, **kwargs): + # TODO: b/483025864 - use https://github.com/bazelbuild/rules_cc/commit/011d6d9e7fae71d43df2d4d83c577f2cef2aa52e + return cc_common.merge_cc_infos(*args, **kwargs) + _DOCS = struct( ATTRS = { "resources": """ @@ -112,6 +117,7 @@ semantics = struct( for_attribute = lambda name: _DOCS.ATTRS.get(name, ""), ), minimize_cc_info = _minimize_cc_info, + merge_cc_infos = _merge_cc_infos, tokenize_javacopts = _tokenize_javacopts, PLATFORMS_ROOT = "@platforms//", INCOMPATIBLE_DISABLE_NON_EXECUTABLE_JAVA_BINARY = False, # Flip when java_single_jar is feature complete diff --git a/java/private/java_info.bzl b/java/private/java_info.bzl index 65c6f2a1..19c435a2 100644 --- a/java/private/java_info.bzl +++ b/java/private/java_info.bzl @@ -16,7 +16,6 @@ Definition of JavaInfo and JavaPluginInfo provider. """ -load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("//java/common:java_semantics.bzl", "semantics") load(":native.bzl", "get_internal_java_common") @@ -175,7 +174,7 @@ def merge( } if get_internal_java_common().google_legacy_api_enabled(): - cc_info = semantics.minimize_cc_info(cc_common.merge_cc_infos(cc_infos = [p.cc_link_params_info for p in providers])) + cc_info = semantics.minimize_cc_info(semantics.merge_cc_infos(cc_infos = [p.cc_link_params_info for p in providers])) result.update( cc_link_params_info = cc_info, transitive_native_libraries = @@ -677,7 +676,7 @@ def _javainfo_init_base( if get_internal_java_common().google_legacy_api_enabled(): transitive_cc_infos = [dep.cc_link_params_info for dep in concatenated_deps.runtimedeps_exports_deps] transitive_cc_infos.extend(native_libraries) - cc_info = semantics.minimize_cc_info(cc_common.merge_cc_infos(cc_infos = transitive_cc_infos)) + cc_info = semantics.minimize_cc_info(semantics.merge_cc_infos(cc_infos = transitive_cc_infos)) result.update( cc_link_params_info = cc_info, transitive_native_libraries = @@ -686,7 +685,7 @@ def _javainfo_init_base( else: transitive_native_libraries = [] if native_libraries: - merged_cc_info = cc_common.merge_cc_infos(cc_infos = native_libraries) + merged_cc_info = semantics.merge_cc_infos(cc_infos = native_libraries) if hasattr(merged_cc_info, "_legacy_transitive_native_libraries"): transitive_native_libraries = [merged_cc_info._legacy_transitive_native_libraries] else: From 7b13ead48190fc096b61bf1e7aa9df59121212be Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 17 Apr 2026 07:10:56 -0700 Subject: [PATCH 161/251] Support disable_lint_checks in java_library PiperOrigin-RevId: 901279874 Change-Id: Icfebb038e6974b6d9dfc091cfd9e88a27de6aa68 --- java/common/rules/android_lint.bzl | 15 ++++++++++++++- .../common/rules/impl/basic_java_library_impl.bzl | 5 ++++- .../common/rules/impl/bazel_java_library_impl.bzl | 5 ++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/java/common/rules/android_lint.bzl b/java/common/rules/android_lint.bzl index 032e06bc..7152990c 100644 --- a/java/common/rules/android_lint.bzl +++ b/java/common/rules/android_lint.bzl @@ -22,7 +22,18 @@ def _tokenize_opts(opts_depset): opts = reversed(opts_depset.to_list()) return semantics.tokenize_javacopts(opts) -def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_library): +def _flags_from_disable_lint_checks(args, disable_lint_checks): + invalid_ids = [check for check in disable_lint_checks if not _check_id_is_valid(check)] + if invalid_ids: + fail("Found not allowed character in disabled check ID(s) %s" % str(invalid_ids)) + args.add_joined("--disable", disable_lint_checks, join_with = ",") + +# Returns whether the passed Android Lint check ID is valid +def _check_id_is_valid(check): + # We want to prevent whitespace so that extra flags can't be 'injected' into Android Lint + return check.replace(".", "").replace("_", "").isalnum() + +def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_library, disable_lint_checks = []): """ Creates an action that runs Android lint against Java source files. @@ -43,6 +54,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li source files. It should also include generated source jars. compilation_info: (struct) Information about compilation. is_library: (bool) Whether the target is a library. + disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped. Returns: (None|File) The Android lint output file or None if no source files were @@ -112,6 +124,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li args.add("--lintopts") args.add_all(linter.lint_opts) + _flags_from_disable_lint_checks(args, disable_lint_checks) for package_config in linter.package_config: if package_config.matches(package_config.package_specs, ctx.label): diff --git a/java/common/rules/impl/basic_java_library_impl.bzl b/java/common/rules/impl/basic_java_library_impl.bzl index affd222f..e2e27442 100644 --- a/java/common/rules/impl/basic_java_library_impl.bzl +++ b/java/common/rules/impl/basic_java_library_impl.bzl @@ -72,7 +72,8 @@ def basic_java_library( add_opens = [], bootclasspath = None, javabuilder_jvm_flags = None, - is_library = True): + is_library = True, + disable_lint_checks = []): """ Creates actions that compile and lint Java sources, sets up coverage and returns JavaInfo, InstrumentedFilesInfo and output groups. @@ -109,6 +110,7 @@ def basic_java_library( bootclasspath: (Target) The JDK APIs to compile this library against. javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder. is_library: (bool) Whether the target is a library. Primarily for static analysis purposes. + disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped. Returns: (dict[str, Provider], {files_to_build: list[File], @@ -172,6 +174,7 @@ def basic_java_library( source_jars + generated_source_jars, compilation_info, is_library, + disable_lint_checks, ) if lint_output: validation_outputs.append(depset([lint_output])) diff --git a/java/common/rules/impl/bazel_java_library_impl.bzl b/java/common/rules/impl/bazel_java_library_impl.bzl index 5c7fc5cb..3ee1deb7 100644 --- a/java/common/rules/impl/bazel_java_library_impl.bzl +++ b/java/common/rules/impl/bazel_java_library_impl.bzl @@ -35,7 +35,8 @@ def bazel_java_library_rule( add_exports = [], add_opens = [], bootclasspath = None, - javabuilder_jvm_flags = None): + javabuilder_jvm_flags = None, + disable_lint_checks = []): """Implements java_library. Use this call when you need to produce a fully fledged java_library from @@ -58,6 +59,7 @@ def bazel_java_library_rule( add_opens: (list[str]) Allow this library to reflectively access the given /. bootclasspath: (Target) The JDK APIs to compile this library against. javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder. + disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped. Returns: (dict[str, provider]) A list containing DefaultInfo, JavaInfo, InstrumentedFilesInfo, OutputGroupsInfo, ProguardSpecProvider providers. @@ -83,6 +85,7 @@ def bazel_java_library_rule( add_opens = add_opens, bootclasspath = bootclasspath, javabuilder_jvm_flags = javabuilder_jvm_flags, + disable_lint_checks = disable_lint_checks, ) target["DefaultInfo"] = construct_defaultinfo( From e1c82d4942c1150e8037a1d75358b51c57e17d70 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 22 Apr 2026 01:26:25 -0700 Subject: [PATCH 162/251] Internal Change PiperOrigin-RevId: 903683605 Change-Id: Ib9c4b7bdce8dd815722e9ca6916ba3a69743d2da --- java/common/java_semantics.bzl | 4 ++++ java/common/rules/impl/import_deps_check.bzl | 1 + 2 files changed, 5 insertions(+) diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 3a7459ca..e847d879 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -24,6 +24,9 @@ def _find_java_toolchain(ctx): def _find_java_runtime_toolchain(ctx): return ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"].java_runtime +def _update_args_for_import_deps(*_args): + pass + def _get_default_resource_path(path, segment_extractor): # Look for src/.../resources to match Maven repository structure. segments = path.split("/") @@ -121,5 +124,6 @@ semantics = struct( tokenize_javacopts = _tokenize_javacopts, PLATFORMS_ROOT = "@platforms//", INCOMPATIBLE_DISABLE_NON_EXECUTABLE_JAVA_BINARY = False, # Flip when java_single_jar is feature complete + update_args_for_import_deps = _update_args_for_import_deps, expand_javacopts_make_variables = True, ) diff --git a/java/common/rules/impl/import_deps_check.bzl b/java/common/rules/impl/import_deps_check.bzl index 68d52145..69dec8b6 100644 --- a/java/common/rules/impl/import_deps_check.bzl +++ b/java/common/rules/impl/import_deps_check.bzl @@ -57,6 +57,7 @@ def import_deps_check( args.add("--jdeps_output", jdeps_output) args.add("--rule_label", ctx.label) + semantics.update_args_for_import_deps(ctx, args) inputs = depset( jars_to_check, transitive = [ From 23ef409e3b3ec682ce821911676425ed7c293300 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 22 Apr 2026 02:56:23 -0700 Subject: [PATCH 163/251] Migrate the `javaTestSetsSecurityManagerPropertyOnVersion17` to Starlark The test is added to rules_java and removed from Bazel (ignore-relnotes) PiperOrigin-RevId: 903721335 Change-Id: I8cd6b6c86bb32304f63cc1f21fae16f20319eefd --- test/java/common/rules/java_test_tests.bzl | 38 ++++++++++++++++++++++ test/java/testutil/mock_java_toolchain.bzl | 2 ++ 2 files changed, 40 insertions(+) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index f1c44662..d4bd4b0e 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -12,6 +12,7 @@ load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:mock_cc_toolchain.bzl", "mock_cc_toolchain") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_runtime_toolchain") load("//test/java/testutil:mock_test_toolchain.bzl", "mock_test_toolchains") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -315,6 +316,42 @@ def _test_mac_requires_darwin_for_execution_impl(env, target): {"requires-darwin": ""}, ) +def _test_java_test_sets_securiry_manager_property_jdk17(name): + util.helper_target( + java_test, + name = name + "/test", + srcs = ["FooTest.java"], + test_class = "FooTest", + ) + util.helper_target( + mock_java_runtime_toolchain, + name = name + "/toolchain", + version = 17, + ) + + analysis_test( + name = name, + impl = _test_java_test_sets_securiry_manager_property_jdk17_impl, + target = name + "/test", + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_java_test_sets_securiry_manager_property_jdk17_impl(env, target): + executable = env.expect.that_target(target).executable().actual.short_path + assert_action = env.expect.that_target(target).action_generating(executable) + if assert_action.actual.substitutions: + # TemplateExpansion action on linux/mac + assert_action.substitutions().get("%jvm_flags%", factory = subjects.str).contains( + "-Djava.security.manager=allow", + ) + else: + # windows + assert_action.argv().contains_predicate( + matching.str_matches("-Djava.security.manager=allow"), + ) + def java_test_tests(name): test_suite( name = name, @@ -327,5 +364,6 @@ def java_test_tests(name): _test_stamp_values, _test_add_test_support_to_compile_time_deps_flag, _test_mac_requires_darwin_for_execution, + _test_java_test_sets_securiry_manager_property_jdk17, ], ) diff --git a/test/java/testutil/mock_java_toolchain.bzl b/test/java/testutil/mock_java_toolchain.bzl index c0ca6317..de824b16 100644 --- a/test/java/testutil/mock_java_toolchain.bzl +++ b/test/java/testutil/mock_java_toolchain.bzl @@ -46,12 +46,14 @@ def mock_java_runtime_toolchain( srcs = [], java_home = None, java = None, + version = None, **kwargs): _java_runtime_rule( name = name + "_runtime", srcs = srcs, java_home = java_home, java = java, + version = version, **kwargs ) native.toolchain( From d07df79ee172b2ef06af50966b3af052fee2e68f Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 27 Apr 2026 01:27:20 -0700 Subject: [PATCH 164/251] Migrate the `testResourceStripPrefix` test to Starlark The test is removed from Bazel and added to rules_java (ignore-relnotes) PiperOrigin-RevId: 906200503 Change-Id: I2feea71ecbe4b2741a00a32503d10dc63d181eb9 --- test/java/bazel/rules/java_binary_tests.bzl | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 737acea9..8c385046 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -97,6 +97,27 @@ def _test_java_binary_javacopts_location_expansion_impl(env, target): "-XepOpt:foo={package}/A.java", ) +def _test_java_binary_resource_strip_prefix(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Foo.java"], + main_class = "Foo", + resource_strip_prefix = native.package_name() + "/path/to/strip", + resources = ["path/to/strip/bar.props"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_resource_strip_prefix_impl, + target = name + "/bin", + ) + +def _test_java_binary_resource_strip_prefix_impl(env, target): + env.expect.that_target(target).action_generating("{package}/{name}.jar").contains_flag_values([ + ("--resources", "{package}/path/to/strip/bar.props:bar.props"), + ]) + def java_binary_tests(name): test_suite( name = name, @@ -104,5 +125,6 @@ def java_binary_tests(name): _test_java_binary_cross_compilation_to_unix, _test_java_binary_javacopts_make_variable_expansion, _test_java_binary_javacopts_location_expansion, + _test_java_binary_resource_strip_prefix, ], ) From 0b519df0fb588dc06b89dfe4d50d7639c1ce73a6 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 29 Apr 2026 08:04:46 -0700 Subject: [PATCH 165/251] Add java_library tests (ignore-relnotes) PiperOrigin-RevId: 907592868 Change-Id: I95b3560ff3008b56d5d2d63dbbd7eb8f91d2911a --- .../common_launcher_java_library_tests.bzl | 401 ++++++++++++++++++ test/java/testutil/javac_action_subject.bzl | 7 + 2 files changed, 408 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index 9690b2ba..3b2a2282 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -1,13 +1,19 @@ """Parameterized tests for java_library with --java_launcher""" load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_import.bzl", "java_import") load("//java:java_library.bzl", "java_library") +load("//java:java_plugin.bzl", "java_plugin") +load("//java/toolchains:java_runtime.bzl", "java_runtime") +load("//java/toolchains:java_toolchain.bzl", "java_toolchain") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") +load("//test/java/testutil:rules/custom_library_with_bootclasspath.bzl", "custom_bootclasspath") def _test_java_library_rule_outputs(name): util.helper_target( @@ -214,12 +220,397 @@ def _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation expected_compile = "{bin_path}/{package}/lib{test_name}/compile_dep-hjar.jar" javac_action_subject.of(env, target, "{package}/lib{name}.jar").classpath().contains_exactly([expected_compile]) +def _test_java_library_annotation_processing_using_javacopt(name): + util.helper_target( + java_library, + name = name + "/to_be_processed", + srcs = ["ToBeProcessed.java"], + javacopts = ["-processor com.google.process.Processor"], + ) + + analysis_test( + name = name, + impl = _test_java_library_annotation_processing_using_javacopt_impl, + target = name + "/to_be_processed", + ) + +def _test_java_library_annotation_processing_using_javacopt_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.argv().contains("--generated_sources_output") + javac_action.generated_sources_output().contains("{bin_path}/{package}/lib{name}-gensrc.jar") + javac_action.javacopts().contains("-processor") + javac_action.javacopts().contains("com.google.process.Processor") + + # The compile action should have a gensrc jar output + javac_action.outputs().contains("{package}/lib{name}-gensrc.jar") + + # The gensrc jar should be an input to the source jar action + src_jar_action = env.expect.that_target(target).action_generating("{package}/lib{name}-src.jar") + src_jar_action.inputs().contains("{package}/lib{name}-gensrc.jar") + +def _test_java_library_javacopts_with_location_expansion(name): + util.helper_target( + java_library, + name = name + "/patch", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["ToBeProcessed.java"], + javacopts = ["--patch $(execpath " + name + "/patch)"], + deps = [name + "/patch"], + ) + + analysis_test( + name = name, + impl = _test_java_library_javacopts_with_location_expansion_impl, + target = name + "/lib", + ) + +def _test_java_library_javacopts_with_location_expansion_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.javacopts().contains_at_least([ + "--patch", + "{bin_path}/{package}/lib{test_name}/patch.jar", + ]) + +def _test_java_library_invalid_plugin(name): + util.helper_target( + java_library, + name = name + "/not_a_plugin", + srcs = ["NotAPlugin.java"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Lib.java"], + plugins = [name + "/not_a_plugin"], + ) + + analysis_test( + name = name, + impl = _test_java_library_invalid_plugin_impl, + target = name + "/lib", + expect_failure = True, + ) + +def _test_java_library_invalid_plugin_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("does not have mandatory providers: 'JavaPluginInfo'"), + ) + +def _test_java_library_plugin_with_runtime_deps(name): + util.helper_target( + java_library, + name = name + "/runtime_lib", + srcs = ["Runtime.java"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Lib.java"], + runtime_deps = [name + "/runtime_lib"], + ) + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + processor_class = "com.google.process.stuff", + deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/leaf_lib", + srcs = ["LeafLib.java"], + plugins = [name + "/plugin"], + ) + + analysis_test( + name = name, + impl = _test_java_library_plugin_with_runtime_deps_impl, + target = name + "/leaf_lib", + ) + +def _test_java_library_plugin_with_runtime_deps_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.processorpath().contains_exactly_predicates([ + matching.str_matches("*/plugin.jar"), + matching.str_matches("*/lib.jar"), + matching.str_matches("*/runtime_lib.jar"), + ]) + +def _test_java_library_source_jar_without_annotation_processing(name): + util.helper_target( + java_library, + name = name + "/foo", + srcs = ["Foo.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_source_jar_without_annotation_processing_impl, + target = name + "/foo", + ) + +def _test_java_library_source_jar_without_annotation_processing_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.argv().not_contains("--generated_sources_output") + javac_action.outputs().contains_exactly([ + "{package}/lib{name}.jar", + "{package}/lib{name}.jdeps", + "{package}/lib{name}-native-header.jar", + "{package}/lib{name}.jar_manifest_proto", + ]) + + src_jar_action = javac_action_subject.of(env, target, "{package}/lib{name}-src.jar") + src_jar_action.outputs().contains_exactly([ + "{package}/lib{name}-src.jar", + ]) + +def _test_java_library_source_jars_with_source_jars(name): + util.helper_target( + java_library, + name = name + "/beatit", + srcs = [ + "Plugin.java", + "Some.srcjar", + ], + ) + + analysis_test( + name = name, + impl = _test_java_library_source_jars_with_source_jars_impl, + target = name + "/beatit", + ) + +def _test_java_library_source_jars_with_source_jars_impl(env, target): + src_jar_action = javac_action_subject.of(env, target, "{package}/lib{name}-src.jar") + src_jar_action.inputs().contains_at_least([ + "{package}/Plugin.java", + "{package}/Some.srcjar", + ]) + src_jar_action.sources().contains_exactly([ + "{package}/Some.srcjar", + ]) + src_jar_action.resources().contains_predicate( + matching.str_matches("*/Plugin.java:*rules/Plugin.java"), + ) + +def _test_java_library_should_set_bootclasspath(name): + boot_jar = util.empty_file(name + "/boot.jar") + util.helper_target( + custom_bootclasspath, + name = name + "/mock_bootclasspath", + bootclasspath = [boot_jar], + ) + + util.helper_target( + java_runtime, + name = name + "/runtime", + ) + + util.helper_target( + java_toolchain, + name = name + "/mock_toolchain_impl", + bootclasspath = [name + "/mock_bootclasspath"], + genclass = name + "/genclass", + header_compiler = name + "/header_compiler", + header_compiler_direct = name + "/header_compiler_direct", + ijar = name + "/ijar", + java_runtime = name + "/runtime", + javabuilder = name + "/javabuilder", + singlejar = name + "/singlejar", + ) + util.helper_target( + native.toolchain, + name = name + "/toolchain", + toolchain = name + "/mock_toolchain_impl", + toolchain_type = "@bazel_tools//tools/jdk:toolchain_type", + ) + util.helper_target( + java_library, + name = name + "/test_lib", + srcs = ["A.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_should_set_bootclasspath_impl, + config_settings = { + "//command_line_option:extra_toolchains": [ + native.package_relative_label(name + "/toolchain"), + ], + }, + target = name + "/test_lib", + ) + +def _test_java_library_should_set_bootclasspath_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + + javac_action.bootclasspath().contains_exactly([ + "{bin_path}/{package}/test_java_library_should_set_bootclasspath/boot.jar", + ]) + +def _test_java_library_command_line_contains_target_label_and_rule_kind(name): + util.helper_target( + java_library, + name = name + "/test_lib", + srcs = ["A.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_command_line_contains_target_label_and_rule_kind_impl, + target = name + "/test_lib", + ) + +def _test_java_library_command_line_contains_target_label_and_rule_kind_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.target_label().contains_exactly(["//{package}:{name}"]) + +def _test_java_library_propagates_native_libraries(name): + util.helper_target( + cc_library, + name = name + "/native_deps1.so", + srcs = ["a.cc"], + ) + util.helper_target( + java_library, + name = name + "/lib_deps", + srcs = ["B.java"], + deps = [name + "/native_deps1.so"], + ) + util.helper_target( + cc_library, + name = name + "/native_deps2.so", + srcs = ["b.cc"], + ) + util.helper_target( + cc_library, + name = name + "/native_rdeps1.so", + srcs = ["c.cc"], + ) + util.helper_target( + java_library, + name = name + "/lib_runtime_deps", + srcs = ["C.java"], + deps = [name + "/native_rdeps1.so"], + ) + util.helper_target( + cc_library, + name = name + "/native_rdeps2.so", + srcs = ["d.cc"], + ) + util.helper_target( + cc_library, + name = name + "/native_exports1.so", + srcs = ["e.cc"], + ) + util.helper_target( + java_library, + name = name + "/lib_exports", + srcs = ["D.java"], + deps = [name + "/native_exports1.so"], + ) + util.helper_target( + cc_library, + name = name + "/native_exports2.so", + srcs = ["f.cc"], + ) + util.helper_target( + cc_library, + name = name + "/native_data1.so", + srcs = ["g.cc"], + ) + util.helper_target( + java_library, + name = name + "/lib_data", + srcs = ["E.java"], + deps = [name + "/native_data1.so"], + ) + util.helper_target( + cc_library, + name = name + "/native_data2.so", + srcs = ["h.cc"], + ) + util.helper_target( + java_library, + name = name + "/top", + srcs = ["A.java"], + data = [ + name + "/lib_data", + name + "/native_data2.so", + ], + exports = [ + name + "/lib_exports", + name + "/native_exports2.so", + ], + runtime_deps = [ + name + "/lib_runtime_deps", + name + "/native_rdeps2.so", + ], + deps = [ + name + "/lib_deps", + name + "/native_deps2.so", + ], + ) + + analysis_test( + name = name, + impl = _test_java_library_propagates_native_libraries_impl, + target = name + "/top", + ) + +def _test_java_library_propagates_native_libraries_impl(env, target): + java_info_subject.from_target(env, target).transitive_native_libraries().static_libraries().contains_exactly_predicates([ + # Windows platforms use .lib extension for static libraries. + matching.is_in(["libnative_rdeps2.so.a", "native_rdeps2.so.lib"]), + matching.is_in(["libnative_exports2.so.a", "native_exports2.so.lib"]), + matching.is_in(["libnative_deps2.so.a", "native_deps2.so.lib"]), + matching.is_in(["libnative_rdeps1.so.a", "native_rdeps1.so.lib"]), + matching.is_in(["libnative_exports1.so.a", "native_exports1.so.lib"]), + matching.is_in(["libnative_deps1.so.a", "native_deps1.so.lib"]), + ]) + +def _test_java_library_gen_source_no_processor_names(name): + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["AnnotationProcessor.java"], + ) + util.helper_target( + java_library, + name = name + "/to_be_processed", + srcs = ["ToBeProcessed.java"], + plugins = [name + "/plugin"], + ) + + analysis_test( + name = name, + impl = _test_java_library_gen_source_no_processor_names_impl, + target = name + "/to_be_processed", + ) + +def _test_java_library_gen_source_no_processor_names_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + + # The compile action should not have a gensrc jar output even though it has a plugin, + # since the plugin doesn't define a processor. + javac_action.outputs().contains_exactly([ + "{package}/lib{name}.jar", + "{package}/lib{name}.jdeps", + "{package}/lib{name}-native-header.jar", + "{package}/lib{name}.jar_manifest_proto", + ]) + def _test_java_library_fix_deps_tool_written_to_params_file(name): if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: # Bazel 7 does not support transition on experimental_* flags. # Exit early because this test case would be a loading phase error otherwise. always_passes(name) return + util.helper_target( java_library, name = name + "/base", @@ -250,4 +641,14 @@ JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_runtime_deps_are_not_on_classpath, _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation, _test_java_library_fix_deps_tool_written_to_params_file, + _test_java_library_propagates_native_libraries, + _test_java_library_gen_source_no_processor_names, + _test_java_library_annotation_processing_using_javacopt, + _test_java_library_javacopts_with_location_expansion, + _test_java_library_invalid_plugin, + _test_java_library_plugin_with_runtime_deps, + _test_java_library_source_jar_without_annotation_processing, + _test_java_library_source_jars_with_source_jars, + _test_java_library_should_set_bootclasspath, + _test_java_library_command_line_contains_target_label_and_rule_kind, ] diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 057040b0..3c405665 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -25,9 +25,16 @@ def _new_javac_action_subject(env, target, output): # An unset --strict_java_deps is equivalent to "OFF". strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), + resources = lambda: _create_subject_for_flag("--resources", self.parsed_flags, self.meta), classpath = lambda: _create_subject_for_flag("--classpath", self.parsed_flags, self.meta), + bootclasspath = lambda: _create_subject_for_flag("--bootclasspath", self.parsed_flags, self.meta), + system = lambda: _create_subject_for_flag("--system", self.parsed_flags, self.meta), + generated_sources_output = lambda: _create_subject_for_flag("--generated_sources_output", self.parsed_flags, self.meta), + processorpath = lambda: _create_subject_for_flag("--processorpath", self.parsed_flags, self.meta), + target_label = lambda: _create_subject_for_flag("--target_label", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, + outputs = lambda: subjects.collection([o.short_path for o in action_subject.actual.outputs.to_list()], self.meta.derive("outputs()"), format = True), argv = action_subject.argv, mnemonic = action_subject.mnemonic, ) From 6d7ddaa95b786b47815ce1ff41d16d1b880e4b99 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 29 Apr 2026 08:39:11 -0700 Subject: [PATCH 166/251] Add java_library tests (ignore-relnotes) PiperOrigin-RevId: 907608297 Change-Id: I972c3eb8e2a85812809adec31e521077c1c5c785 --- test/java/common/rules/BUILD | 21 ++ .../common_launcher_java_library_tests.bzl | 232 ++++++++++++++++++ test/java/testutil/java_info_subject.bzl | 1 + test/java/testutil/javac_action_subject.bzl | 1 + 4 files changed, 255 insertions(+) diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 28d38349..0f1d293c 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -1,3 +1,5 @@ +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") load(":add_exports_tests.bzl", "add_exports_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") @@ -30,3 +32,22 @@ java_single_jar_tests(name = "java_single_jar_tests") java_test_tests(name = "java_test_tests") add_exports_tests(name = "add_exports_tests") + +# Used for tests. +util.helper_target( + java_library, + name = "module_javacopts_helper", + srcs = [ + "InputFile.java", + "InputFile2.java", + ], + add_exports = [ + "export/one", + "export/two", + ], + add_opens = [ + "open/one", + "open/two", + ], + visibility = ["//test/java:__subpackages__"], +) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index 3b2a2282..f0a19580 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -13,6 +13,7 @@ load("//java/toolchains:java_toolchain.bzl", "java_toolchain") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") load("//test/java/testutil:rules/custom_library_with_bootclasspath.bzl", "custom_bootclasspath") def _test_java_library_rule_outputs(name): @@ -632,6 +633,230 @@ def _test_java_library_fix_deps_tool_written_to_params_file_impl(env, target): "fixer", ]).in_order() +def _test_java_library_compilation_info_provider(name): + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + bootclasspath = [name + "/boot.jar"], + ) + + util.helper_target( + java_library, + name = name + "/test_lib", + srcs = ["A.java"], + ) + + analysis_test( + name = name, + impl = _test_java_library_compilation_info_provider_impl, + config_settings = { + "//command_line_option:extra_toolchains": [ + native.package_relative_label(name + "/toolchain"), + ], + }, + target = name + "/test_lib", + ) + +def _test_java_library_compilation_info_provider_impl(env, target): + java_info_subject.from_target(env, target).compilation_info().boot_classpath().contains_exactly([ + "{package}/{test_name}/boot.jar", + ]) + +def _test_java_library_native_header_outputs(name): + util.helper_target( + java_library, + name = name + "/jni", + srcs = [ + "Bar.java", + "Foo.java", + ], + ) + + analysis_test( + name = name, + impl = _test_java_library_native_header_outputs_impl, + target = name + "/jni", + ) + +def _test_java_library_native_header_outputs_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.native_header_output().contains_exactly([ + "{bin_path}/{package}/lib{name}-native-header.jar", + ]) + javac_action.outputs().contains("{package}/lib{name}-native-header.jar") + java_info_subject.from_target(env, target).outputs().native_headers().contains_exactly([ + "{package}/lib{name}-native-header.jar", + ]) + +def _test_java_library_module_javacopts(name): + analysis_test( + name = name, + impl = _test_java_library_module_javacopts_impl, + target = "//test/java/common/rules:module_javacopts_helper", + ) + +def _test_java_library_module_javacopts_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.javacopts().contains_at_least([ + "--add-exports=export/one=ALL-UNNAMED", + "--add-exports=export/two=ALL-UNNAMED", + ]) + + java_info = java_info_subject.from_target(env, target) + java_info.module_flags().add_exports().contains_exactly([ + "export/one", + "export/two", + ]) + java_info.module_flags().add_opens().contains_exactly([ + "open/one", + "open/two", + ]) + +def _test_java_library_forwarded_deps(name): + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + util.helper_target( + java_library, + name = name + "/b1", + exports = [name + "/a"], + ) + util.helper_target( + java_library, + name = name + "/b2", + exports = [name + "/a"], + ) + util.helper_target( + java_library, + name = name + "/c1", + srcs = ["c1.java"], + deps = [name + "/b1"], + ) + util.helper_target( + java_library, + name = name + "/c2", + srcs = ["c2.java"], + deps = [name + "/b2"], + ) + + analysis_test( + name = name, + impl = _test_java_library_forwarded_deps_impl, + targets = { + "a": name + "/a", + "c1": name + "/c1", + "c2": name + "/c2", + }, + ) + +def _test_java_library_forwarded_deps_impl(env, targets): + a_info = java_info_subject.from_target(env, targets.a) + c1_info = java_info_subject.from_target(env, targets.c1) + c2_info = java_info_subject.from_target(env, targets.c2) + + a_jars = a_info.compilation_args().actual.compile_jars.to_list() + c1_info.compilation_info().compilation_classpath().contains_at_least(a_jars) + c2_info.compilation_info().compilation_classpath().contains_at_least(a_jars) + +# Regression test for b/5773894 +def _test_java_library_transitive_strict_deps(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + + util.helper_target( + java_library, + name = name + "/c", + srcs = ["C.java"], + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + deps = [name + "/c"], + ) + util.helper_target( + java_library, + name = name + "/a", + exports = [name + "/b"], + ) + + analysis_test( + name = name, + impl = _test_java_library_transitive_strict_deps_impl, + config_settings = { + "//command_line_option:experimental_strict_java_deps": "ERROR", + }, + target = name + "/a", + ) + +def _test_java_library_transitive_strict_deps_impl(env, target): + a_info = java_info_subject.from_target(env, target) + a_info.compilation_args().compile_jars().contains_exactly([ + "{package}/lib{test_name}/b-hjar.jar", + ]) + +def _test_java_library_emit_output_deps(name): + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + ) + util.helper_target( + java_library, + name = name + "/a", + exports = [name + "/b"], + ) + + analysis_test( + name = name, + impl = _test_java_library_emit_output_deps_impl, + config_settings = { + "//command_line_option:java_deps": True, + }, + targets = { + "a": name + "/a", + "b": name + "/b", + }, + ) + +def _test_java_library_emit_output_deps_impl(env, targets): + javac_action_subject.of(env, targets.b, "{package}/lib{name}.jar").outputs().contains( + "{package}/lib{name}.jdeps", + ) + + javac_action_subject.of(env, targets.a, "{package}/lib{name}.jar").outputs().contains_exactly([ + "{package}/lib{name}.jar", + "{package}/lib{name}-native-header.jar", + "{package}/lib{name}.jar_manifest_proto", + ]) + +def _test_java_library_deps_without_srcs(name): + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + ) + util.helper_target( + java_library, + name = name + "/a", + deps = [name + "/b"], + ) + + analysis_test( + name = name, + impl = _test_java_library_deps_without_srcs_impl, + target = name + "/a", + expect_failure = True, + ) + +def _test_java_library_deps_without_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("deps not allowed without srcs"), + ) + JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_rule_outputs, _test_java_library_action_graph, @@ -651,4 +876,11 @@ JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_source_jars_with_source_jars, _test_java_library_should_set_bootclasspath, _test_java_library_command_line_contains_target_label_and_rule_kind, + _test_java_library_compilation_info_provider, + _test_java_library_native_header_outputs, + _test_java_library_module_javacopts, + _test_java_library_forwarded_deps, + _test_java_library_transitive_strict_deps, + _test_java_library_emit_output_deps, + _test_java_library_deps_without_srcs, ] diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index f5ad9e9c..9a0fb533 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -57,6 +57,7 @@ def _new_java_compilation_info_subject(java_info, meta): ) public = struct( compilation_classpath = lambda: subjects.depset_file(self.actual.compilation_classpath, self.meta.derive("compilation_classpath")), + boot_classpath = lambda: subjects.depset_file(self.actual.boot_classpath, self.meta.derive("boot_classpath")), runtime_classpath = lambda: subjects.depset_file(self.actual.runtime_classpath, self.meta.derive("runtime_classpath")), runtime_classpath_list = lambda: subjects.collection(self.actual.runtime_classpath.to_list(), self.meta.derive("runtime_classpath.to_list()"), format = True), javac_options = lambda: subjects.collection(helper.tokenize_javacopts(opts = self.actual.javac_options), self.meta.derive("javac_options"), format = True), diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 3c405665..ab957abe 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -37,6 +37,7 @@ def _new_javac_action_subject(env, target, output): outputs = lambda: subjects.collection([o.short_path for o in action_subject.actual.outputs.to_list()], self.meta.derive("outputs()"), format = True), argv = action_subject.argv, mnemonic = action_subject.mnemonic, + native_header_output = lambda: _create_subject_for_flag("--native_header_output", self.parsed_flags, self.meta), ) return public From 2e11dbd09b5c6fdcee276b11053baaf78f1d5647 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 30 Apr 2026 01:34:18 -0700 Subject: [PATCH 167/251] Fix `@rules_java` CI with `Bazel@HEAD`. Broken by https://github.com/bazelbuild/bazel/commit/905d8e09e4b8dc7333ecd7f4621c7d98f55948a2 [^1] (ignore-relnotes) PiperOrigin-RevId: 908023960 Change-Id: I113d44af93935dbee4cc4d5c534799f034d4dfff --- .../common_launcher_java_library_tests.bzl | 29 ------------------- test/java/common/rules/java_test_tests.bzl | 27 ----------------- 2 files changed, 56 deletions(-) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index f0a19580..fe17a7b0 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -605,34 +605,6 @@ def _test_java_library_gen_source_no_processor_names_impl(env, target): "{package}/lib{name}.jar_manifest_proto", ]) -def _test_java_library_fix_deps_tool_written_to_params_file(name): - if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: - # Bazel 7 does not support transition on experimental_* flags. - # Exit early because this test case would be a loading phase error otherwise. - always_passes(name) - return - - util.helper_target( - java_library, - name = name + "/base", - srcs = ["Base.java"], - ) - - analysis_test( - name = name, - impl = _test_java_library_fix_deps_tool_written_to_params_file_impl, - config_settings = { - "//command_line_option:experimental_fix_deps_tool": "fixer", - }, - target = name + "/base", - ) - -def _test_java_library_fix_deps_tool_written_to_params_file_impl(env, target): - javac_action_subject.of(env, target, "{package}/lib{name}.jar").argv().contains_at_least([ - "--experimental_fix_deps_tool", - "fixer", - ]).in_order() - def _test_java_library_compilation_info_provider(name): util.helper_target( mock_java_toolchain, @@ -865,7 +837,6 @@ JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_files_to_compile, _test_java_library_runtime_deps_are_not_on_classpath, _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation, - _test_java_library_fix_deps_tool_written_to_params_file, _test_java_library_propagates_native_libraries, _test_java_library_gen_source_no_processor_names, _test_java_library_annotation_processing_using_javacopt, diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index d4bd4b0e..6c71d335 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -67,32 +67,6 @@ def _test_deps_without_srcs_fails_impl(env, target): matching.contains("deps not allowed without srcs"), ) -def _test_fix_deps_tool(name): - if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: - always_passes(name) - return - util.helper_target( - rule = java_test, - name = name + "/test", - srcs = [name + "/Test.java"], - ) - - analysis_test( - name = name, - target = name + "/test", - impl = _test_fix_deps_tool_impl, - config_settings = { - "//command_line_option:experimental_fix_deps_tool": "customfixer", - }, - ) - -def _test_fix_deps_tool_impl(env, target): - assert_compile_action = env.expect.that_target(target).action_named("Javac") - assert_compile_action.argv().contains_at_least([ - "--experimental_fix_deps_tool", - "customfixer", - ]).in_order() - def _test_java_test_propagates_direct_native_libraries(name): util.helper_target( cc_library, @@ -358,7 +332,6 @@ def java_test_tests(name): tests = [ _test_java_test_is_test_only, _test_deps_without_srcs_fails, - _test_fix_deps_tool, _test_java_test_propagates_direct_native_libraries, _test_coverage_uses_coverage_runner_for_main, _test_stamp_values, From 206ebe3ce99cfebc65d420ccab1e7f50174336a4 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 4 May 2026 09:28:30 -0700 Subject: [PATCH 168/251] Add java_library tests (ignore-relnotes) PiperOrigin-RevId: 910074524 Change-Id: If420bab81faef3164e323355e5e1c4a1647891c8 --- .../common_launcher_java_library_tests.bzl | 275 +++++++++++++++++- test/java/testutil/javac_action_subject.bzl | 2 + .../testutil/javac_action_subject_tests.bzl | 8 + 3 files changed, 284 insertions(+), 1 deletion(-) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index fe17a7b0..b1faa10b 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -317,7 +317,7 @@ def _test_java_library_plugin_with_runtime_deps(name): java_plugin, name = name + "/plugin", srcs = ["Plugin.java"], - processor_class = "com.google.process.stuff", + processor_class = "com.example.process.stuff", deps = [name + "/lib"], ) util.helper_target( @@ -829,6 +829,273 @@ def _test_java_library_deps_without_srcs_impl(env, target): matching.contains("deps not allowed without srcs"), ) +def _test_dependency_artifacts_with_exports(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + + util.helper_target( + java_library, + name = name + "/e", + srcs = ["E.java"], + ) + util.helper_target( + java_library, + name = name + "/d", + srcs = ["D.java"], + ) + util.helper_target( + java_library, + name = name + "/c", + srcs = ["C.java"], + exports = [name + "/e"], + ) + util.helper_target( + java_library, + name = name + "/b", + exports = [name + "/d"], + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["A.java"], + deps = [ + name + "/b", + name + "/c", + name + "/d", + ], + ) + + analysis_test( + name = name, + impl = _test_dependency_artifacts_with_exports_impl, + target = name + "/a", + config_settings = { + "//command_line_option:experimental_java_classpath": "javabuilder", + }, + ) + +def _test_dependency_artifacts_with_exports_impl(env, target): + javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") + javac_action.deps_artifacts().contains_exactly([ + "{bin_path}/{package}/lib{test_name}/c-hjar.jdeps", + "{bin_path}/{package}/lib{test_name}/d-hjar.jdeps", + "{bin_path}/{package}/lib{test_name}/e-hjar.jdeps", + ]) + +def _test_exports_are_indirect_not_direct(name): + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["b.java"], + exports = [name + "/a"], + ) + util.helper_target( + java_library, + name = name + "/c", + srcs = ["c.java"], + deps = [name + "/b"], + ) + + analysis_test( + name = name, + impl = _test_exports_are_indirect_not_direct_impl, + targets = { + "b": name + "/b", + "c": name + "/c", + }, + ) + +def _test_exports_are_indirect_not_direct_impl(env, targets): + b_info = java_info_subject.from_target(env, targets.b) + c_info = java_info_subject.from_target(env, targets.c) + + b_info.compilation_info().compilation_classpath().contains_exactly([]) + + c_info.compilation_info().compilation_classpath().contains_at_least_predicates([ + matching.file_basename_equals("a-hjar.jar"), + matching.file_basename_equals("b-hjar.jar"), + ]) + +def _test_exports_runfiles(name): + util.helper_target( + java_library, + name = name + "/a", + srcs = ["a.java"], + data = ["data.txt"], + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["b.java"], + exports = [name + "/a"], + ) + + analysis_test( + name = name, + impl = _test_exports_runfiles_impl, + target = name + "/b", + ) + +def _test_exports_runfiles_impl(env, target): + env.expect.that_target(target).runfiles().contains_exactly([ + "{workspace}/{package}/data.txt", + "{workspace}/{package}/lib{test_name}/a.jar", + "{workspace}/{package}/lib{test_name}/b.jar", + ]) + +def _test_exports_collect_source_jars(name): + util.helper_target( + java_library, + name = name + "/exp", + srcs = ["C.java"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["B.java"], + exports = [name + "/exp"], + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = ["A.java"], + deps = [name + "/lib"], + ) + + analysis_test( + name = name, + impl = _test_exports_collect_source_jars_impl, + target = name + "/a", + ) + +def _test_exports_collect_source_jars_impl(env, target): + java_info_subject.from_target(env, target).transitive_source_jars().contains_exactly([ + "{package}/lib{test_name}/a-src.jar", + "{package}/lib{test_name}/lib-src.jar", + "{package}/lib{test_name}/exp-src.jar", + ]) + +def _test_exported_plugins_are_inherited(name): + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + processor_class = "com.example.process.stuff", + ) + util.helper_target( + java_library, + name = name + "/exporting_lib", + srcs = ["ExportingLib.java"], + exported_plugins = [name + "/plugin"], + ) + util.helper_target( + java_library, + name = name + "/consuming_lib", + srcs = ["ConsumingLib.java"], + deps = [name + "/exporting_lib"], + ) + util.helper_target( + java_library, + name = name + "/leaf_lib", + srcs = ["LeafLib.java"], + deps = [name + "/consuming_lib"], + ) + + analysis_test( + name = name, + impl = _test_exported_plugins_are_inherited_impl, + targets = { + "consuming": name + "/consuming_lib", + "leaf": name + "/leaf_lib", + }, + ) + +def _test_exported_plugins_are_inherited_impl(env, targets): + # libconsuming_lib should include the plugin, since it directly depends on exporting_lib + javac_action_subject.of( + env, + targets.consuming, + "{package}/lib{test_name}/consuming_lib.jar", + ).processors().contains_exactly(["com.example.process.stuff"]) + + # but libleaf_lib should not, because its dependency is transitive. + javac_action_subject.of( + env, + targets.leaf, + "{package}/lib{test_name}/leaf_lib.jar", + ).processors().contains_exactly([]) + +def _test_exported_plugins_are_propagated_through_exports(name): + util.helper_target( + java_plugin, + name = name + "/plugin", + srcs = ["Plugin.java"], + processor_class = "com.example.process.stuff", + ) + util.helper_target( + java_library, + name = name + "/exporting_plugins_lib", + srcs = ["ExportingLib.java"], + exported_plugins = [name + "/plugin"], + ) + util.helper_target( + java_library, + name = name + "/exporting_lib", + srcs = ["ExportingLib.java"], + exports = [name + "/exporting_plugins_lib"], + ) + util.helper_target( + java_library, + name = name + "/consuming_lib", + srcs = ["ConsumingLib.java"], + exports = [name + "/exporting_lib"], + deps = [name + "/exporting_lib"], + ) + util.helper_target( + java_library, + name = name + "/leaf_lib", + srcs = ["LeafLib.java"], + deps = [name + "/consuming_lib"], + ) + + analysis_test( + name = name, + impl = _test_exported_plugins_are_propagated_through_exports_impl, + targets = { + "exporting": name + "/exporting_lib", + "consuming": name + "/consuming_lib", + "leaf": name + "/leaf_lib", + }, + ) + +def _test_exported_plugins_are_propagated_through_exports_impl(env, targets): + # libexporting_lib should not include the plugin, only export it further. + javac_action_subject.of( + env, + targets.exporting, + "{package}/lib{test_name}/exporting_lib.jar", + ).processors().contains_exactly([]) + + # libconsuming_lib should pick up the plugin through the export on exporting_lib. + javac_action_subject.of( + env, + targets.consuming, + "{package}/lib{test_name}/consuming_lib.jar", + ).processors().contains_exactly(["com.example.process.stuff"]) + + # libleaf_lib should pick up the plugin through the (transitive) export on exporting_lib. + javac_action_subject.of( + env, + targets.leaf, + "{package}/lib{test_name}/leaf_lib.jar", + ).processors().contains_exactly(["com.example.process.stuff"]) + JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_rule_outputs, _test_java_library_action_graph, @@ -854,4 +1121,10 @@ JAVA_LIBRARY_LAUNCHER_TESTS = [ _test_java_library_transitive_strict_deps, _test_java_library_emit_output_deps, _test_java_library_deps_without_srcs, + _test_dependency_artifacts_with_exports, + _test_exports_are_indirect_not_direct, + _test_exports_runfiles, + _test_exports_collect_source_jars, + _test_exported_plugins_are_inherited, + _test_exported_plugins_are_propagated_through_exports, ] diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index ab957abe..a887d689 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -20,6 +20,7 @@ def _new_javac_action_subject(env, target, output): public = struct( direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), + deps_artifacts = lambda: _create_subject_for_flag("--deps_artifacts", self.parsed_flags, self.meta), javacopts = lambda: _create_subject_for_flag("--javacopts", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), # An unset --strict_java_deps is equivalent to "OFF". @@ -31,6 +32,7 @@ def _new_javac_action_subject(env, target, output): system = lambda: _create_subject_for_flag("--system", self.parsed_flags, self.meta), generated_sources_output = lambda: _create_subject_for_flag("--generated_sources_output", self.parsed_flags, self.meta), processorpath = lambda: _create_subject_for_flag("--processorpath", self.parsed_flags, self.meta), + processors = lambda: _create_subject_for_flag("--processors", self.parsed_flags, self.meta, default = []), target_label = lambda: _create_subject_for_flag("--target_label", self.parsed_flags, self.meta), executable_file_name = lambda: subjects.str(action_subject.actual.argv[0], self.meta), inputs = action_subject.inputs, diff --git a/test/java/testutil/javac_action_subject_tests.bzl b/test/java/testutil/javac_action_subject_tests.bzl index c1e577be..dc8f3f47 100644 --- a/test/java/testutil/javac_action_subject_tests.bzl +++ b/test/java/testutil/javac_action_subject_tests.bzl @@ -35,6 +35,12 @@ def _parse_flags_test_impl(ctx): "--classpath", "pkg/bar-hjar.jar", "other/pkg/baz.jar", + "--processors", + "com.example.process.stuff", + "com.example.process.other", + "--deps_artifacts", + "pkg/dep1.jdeps", + "pkg/dep2.jdeps", ]) asserts.equals(env, { "-Xmx1g": [], @@ -64,6 +70,8 @@ def _parse_flags_test_impl(ctx): ], "--strict_java_deps": ["ERROR"], "--classpath": ["pkg/bar-hjar.jar", "other/pkg/baz.jar"], + "--processors": ["com.example.process.stuff", "com.example.process.other"], + "--deps_artifacts": ["pkg/dep1.jdeps", "pkg/dep2.jdeps"], }, flags) return unittest.end(env) From 1f939098d31726416fe22aacb5532ebc3afa3859 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 5 May 2026 07:57:06 -0700 Subject: [PATCH 169/251] Open source one version tests (ignore-relnotes) PiperOrigin-RevId: 910688799 Change-Id: Ifa9ae668c58137ff14eb2aa1a2875c8ac5fe0b37 --- java/common/BUILD | 5 +- java/common/java_semantics.bzl | 2 + test/java/common/rules/java_binary_tests.bzl | 159 +++++++++++++++++++ test/java/common/rules/java_test_tests.bzl | 112 ++++++++++++- test/java/testutil/mock_java_toolchain.bzl | 10 +- 5 files changed, 285 insertions(+), 3 deletions(-) diff --git a/java/common/BUILD b/java/common/BUILD index 9881236a..7887b1f0 100644 --- a/java/common/BUILD +++ b/java/common/BUILD @@ -36,7 +36,10 @@ bzl_library( name = "semantics_bzl", srcs = ["java_semantics.bzl"], visibility = ["//visibility:public"], - deps = ["@rules_cc//cc/common:cc_helper_bzl"], + deps = [ + "@bazel_features//:features", + "@rules_cc//cc/common:cc_helper_bzl", + ], ) bzl_library( diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index e847d879..919553e9 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Bazel Java Semantics""" +load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper") @@ -126,4 +127,5 @@ semantics = struct( INCOMPATIBLE_DISABLE_NON_EXECUTABLE_JAVA_BINARY = False, # Flip when java_single_jar is feature complete update_args_for_import_deps = _update_args_for_import_deps, expand_javacopts_make_variables = True, + java_toolchain_supports_one_version = _bazel_version_ge("8.0.0"), # can be dropped once we no longer support Bazel 7 ) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 7ee9eb1d..f2ab5be9 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -1,6 +1,7 @@ """Tests for the java_binary rule""" load("@bazel_features//:features.bzl", "bazel_features") +load("@bazel_skylib//lib:paths.bzl", "paths") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") @@ -8,9 +9,12 @@ load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") +load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/common/rules:common_launcher_java_binary_tests.bzl", "JAVA_BINARY_LAUNCHER_TESTS") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") load("//test/java/testutil:rules/forward_java_info.bzl", "java_info_forwarding_rule") @@ -250,6 +254,158 @@ def _test_java_binary_can_set_transitive_validation_impl(env, targets): # ensure they don't propagate to `bin` because they're a part of the `deploy_env` env.expect.that_target(targets.bin).output_group("_validation").contains_exactly([]) +def _test_one_version_check_action(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + util.helper_target( + java_library, + name = name + "/c", + srcs = [name + "/c.java"], + ) + util.helper_target( + java_library, + name = name + "/a", + srcs = [name + "/a.java"], + deps = [name + "/c"], + ) + util.helper_target( + java_binary, + name = name + "/b", + srcs = [name + "/b.java"], + deps = [name + "/a"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + oneversion = "one_version_tool", + oneversion_allowlist = "one_version_allowlist", + ) + + analysis_test( + name = name, + impl = _test_one_version_check_action_impl, + target = name + "/b", + config_settings = { + "//command_line_option:experimental_one_version_enforcement": "ERROR", + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + attrs = { + "_windows_constraints": attr.label_list( + default = [paths.join(semantics.PLATFORMS_ROOT, "os:windows")], + ), + }, + ) + +def _test_one_version_check_action_impl(env, target): + assert_target = env.expect.that_target(target) + assert_target.default_outputs().contains_exactly([ + "{package}/{test_name}/b.jar", + "{package}/{test_name}/b" + (".exe" if helper.is_target_platform_windows(env.ctx) else ""), + ]) + assert_target.output_group("_validation").contains( + "{package}/{name}-one-version.txt", + ) + assert_action = assert_target.action_generating("{package}/{name}-one-version.txt") + assert_action.mnemonic().equals("JavaOneVersion") + assert_action.inputs().contains_at_least([ + "{package}/{test_name}/b.jar", + "{package}/lib{test_name}/a.jar", + "{package}/lib{test_name}/c.jar", + ]) + tool = [f for f in assert_action.actual.inputs.to_list() if f.short_path.endswith("one_version_tool")][0] + assert_action.argv().contains_exactly([ + tool.path, + "--output", + "{bindir}/{package}/{name}-one-version.txt", + "--allowlist", + "{package}/one_version_allowlist", + "--inputs", + "{bindir}/{package}/{test_name}/b.jar,//{package}:{test_name}/b", + "{bindir}/{package}/lib{test_name}/a.jar,//{package}:{test_name}/a", + "{bindir}/{package}/lib{test_name}/c.jar,//{package}:{test_name}/c", + ]).in_order() + +def _test_one_version_check_violations_allowed(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/foo", + srcs = [name + "/foo.java"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + oneversion = "one_version_tool", + oneversion_allowlist = "one_version_allowlist", + ) + + analysis_test( + name = name, + impl = _test_one_version_check_violations_allowed_impl, + target = name + "/foo", + config_settings = { + "//command_line_option:experimental_one_version_enforcement": "WARNING", + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_one_version_check_violations_allowed_impl(env, target): + assert_action = env.expect.that_target(target).action_generating( + "{package}/{name}-one-version.txt", + ) + env.expect.that_target(target).output_group("_validation").contains( + "{package}/{name}-one-version.txt", + ) + tool = [f for f in assert_action.actual.inputs.to_list() if f.short_path.endswith("one_version_tool")][0] + assert_action.argv().contains_exactly([ + tool.path, + "--output", + "{bindir}/{package}/{name}-one-version.txt", + "--allowlist", + "{package}/one_version_allowlist", + "--succeed_on_found_violations", + "--inputs", + "{bindir}/{package}/{test_name}/foo.jar,//{package}:{test_name}/foo", + ]).in_order() + +def _test_one_version_check_disabled(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/foo", + srcs = [name + "/foo.java"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + oneversion = "one_version_tool", + ) + + analysis_test( + name = name, + impl = _test_one_version_check_disabled_impl, + target = name + "/foo", + config_settings = { + "//command_line_option:experimental_one_version_enforcement": "OFF", + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_one_version_check_disabled_impl(env, target): + action_mnemonics = [a.mnemonic for a in env.expect.that_target(target).actual.actions] + env.expect.that_collection(action_mnemonics).not_contains("JavaOneVersion") + def java_binary_tests(name): test_suite( name = "_basic_" + name, @@ -260,6 +416,9 @@ def java_binary_tests(name): _test_java_binary_propagates_direct_native_libraries, _test_java_compile_only, _test_java_binary_can_set_transitive_validation, + _test_one_version_check_action, + _test_one_version_check_violations_allowed, + _test_one_version_check_disabled, ], ) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 6c71d335..995872f1 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -1,18 +1,21 @@ """Tests for the java_test rule""" load("@bazel_features//:features.bzl", "bazel_features") +load("@bazel_skylib//lib:paths.bzl", "paths") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:mock_cc_toolchain.bzl", "mock_cc_toolchain") -load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_runtime_toolchain") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_runtime_toolchain", "mock_java_toolchain") load("//test/java/testutil:mock_test_toolchain.bzl", "mock_test_toolchains") load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") @@ -326,6 +329,111 @@ def _test_java_test_sets_securiry_manager_property_jdk17_impl(env, target): matching.str_matches("-Djava.security.manager=allow"), ) +def _test_one_version_check_java_test(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + util.helper_target( + java_library, + name = name + "/foo", + srcs = [name + "/foo.java"], + ) + util.helper_target( + java_test, + name = name + "/foo_test", + srcs = [name + "/foo_test.java"], + deps = [name + "/foo"], + use_testrunner = False, + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + oneversion = "one_version_tool", + oneversion_allowlist = "one_version_allowlist", + oneversion_allowlist_for_tests = "one_version_allowlist_for_tests", + ) + + analysis_test( + name = name, + impl = _test_one_version_check_java_test_impl, + target = name + "/foo_test", + config_settings = { + "//command_line_option:experimental_one_version_enforcement": "ERROR", + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + attrs = { + "_windows_constraints": attr.label_list( + default = [paths.join(semantics.PLATFORMS_ROOT, "os:windows")], + ), + }, + ) + +def _test_one_version_check_java_test_impl(env, target): + assert_target = env.expect.that_target(target) + assert_target.default_outputs().contains_exactly([ + "{package}/{test_name}/foo_test.jar", + "{package}/{test_name}/foo_test" + (".exe" if helper.is_target_platform_windows(env.ctx) else ""), + ]) + assert_action = assert_target.action_generating( + "{package}/{name}-one-version.txt", + ) + tool = [f for f in assert_action.actual.inputs.to_list() if f.short_path.endswith("one_version_tool")][0] + assert_action.argv().contains_exactly([ + tool.path, + "--output", + "{bindir}/{package}/{name}-one-version.txt", + "--allowlist", + "{package}/one_version_allowlist_for_tests", + "--inputs", + "{bindir}/{package}/{test_name}/foo_test.jar,//{package}:{test_name}/foo_test", + "{bindir}/{package}/lib{test_name}/foo.jar,//{package}:{test_name}/foo", + ]).in_order() + +def _test_one_version_check_disabled_for_java_test(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + # exit early because this test case would be a loading phase error otherwise + always_passes(name) + return + + util.helper_target( + java_test, + name = name + "/foo_test", + srcs = [name + "/foo.java"], + use_testrunner = False, + ) + util.helper_target( + java_binary, + name = name + "/foo_binary", + srcs = [name + "/foo.java"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + oneversion = "one_version_tool", + ) + + analysis_test( + name = name, + impl = _test_one_version_check_disabled_for_java_test_impl, + targets = { + "bin": name + "/foo_binary", + "test": name + "/foo_test", + }, + config_settings = { + "//command_line_option:experimental_one_version_enforcement": "ERROR", + "//command_line_option:one_version_enforcement_on_java_tests": False, + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + ) + +def _test_one_version_check_disabled_for_java_test_impl(env, targets): + binary_action_mnemonics = [a.mnemonic for a in env.expect.that_target(targets.bin).actual.actions] + test_action_mnemonics = [a.mnemonic for a in env.expect.that_target(targets.test).actual.actions] + env.expect.that_collection(binary_action_mnemonics).contains("JavaOneVersion") + env.expect.that_collection(test_action_mnemonics).not_contains("JavaOneVersion") + def java_test_tests(name): test_suite( name = name, @@ -338,5 +446,7 @@ def java_test_tests(name): _test_add_test_support_to_compile_time_deps_flag, _test_mac_requires_darwin_for_execution, _test_java_test_sets_securiry_manager_property_jdk17, + _test_one_version_check_java_test, + _test_one_version_check_disabled_for_java_test, ], ) diff --git a/test/java/testutil/mock_java_toolchain.bzl b/test/java/testutil/mock_java_toolchain.bzl index de824b16..aae0afde 100644 --- a/test/java/testutil/mock_java_toolchain.bzl +++ b/test/java/testutil/mock_java_toolchain.bzl @@ -15,11 +15,19 @@ def mock_java_toolchain( ijar = "ijar", genclass = "genclass", java_runtime = None, + oneversion = None, + oneversion_allowlist = None, + oneversion_allowlist_for_tests = None, tags = None, # for util.helper_target **kwargs): if not java_runtime: java_runtime = name + "_runtime" _java_runtime_rule(name = java_runtime) + one_version_args = { + "oneversion": oneversion, + "oneversion_allowlist": oneversion_allowlist, + "oneversion_allowlist_for_tests": oneversion_allowlist_for_tests, + } if semantics.java_toolchain_supports_one_version else {} java_toolchain( name = name + "_java", javabuilder = javabuilder, @@ -30,7 +38,7 @@ def mock_java_toolchain( java_runtime = java_runtime, genclass = genclass, tags = tags, - **kwargs + **(kwargs | one_version_args) ) native.toolchain( name = name, From ffd5c7502ee68292c9c48c8af280710f18122aa1 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 6 May 2026 07:24:59 -0700 Subject: [PATCH 170/251] Migrate the `javaTestInvalidTestClassAtRootPackage` test to Starlark The test is removed from Bazel and added to rules_java (ignore-relnotes) PiperOrigin-RevId: 911323913 Change-Id: Ie7cd3da252158916945911ef1cf59099a098e4e0 --- BUILD | 15 +++++++++++++++ test/java/bazel/rules/java_test_tests.bzl | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/BUILD b/BUILD index 9f0e2239..2fbbbd62 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,5 @@ load("@rules_license//rules:license.bzl", "license") +load("//java:java_test.bzl", "java_test") package(default_applicable_licenses = [":license"]) @@ -27,3 +28,17 @@ license( name = "license", package_name = "rules_java", ) + +# For exercising root-package behavior in tests +java_test( + name = "invalid_test_at_repo_root", + srcs = ["SomeTest.java"], + tags = [ + "manual", + "nobuilder", + "notap", + ], + visibility = [ + "//test/java/bazel/rules:__pkg__", + ], +) diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl index 9ee618d8..5c76b0ee 100644 --- a/test/java/bazel/rules/java_test_tests.bzl +++ b/test/java/bazel/rules/java_test_tests.bzl @@ -35,10 +35,25 @@ def _test_deduced_test_class_impl(env, target): matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.foo"), ) +# regression test for https://github.com/bazelbuild/bazel/issues/20378 +def _test_invalid_test_class_at_repo_root(name): + analysis_test( + name = name, + impl = _test_invalid_test_class_at_repo_root_impl, + target = "//:invalid_test_at_repo_root", + expect_failure = True, + ) + +def _test_invalid_test_class_at_repo_root_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("cannot determine test class."), + ) + def java_test_tests(name): test_suite( name = name, tests = [ _test_deduced_test_class, + _test_invalid_test_class_at_repo_root, ], ) From c54e911d6b351ca25dbba05756ffb98336960346 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 27 May 2026 02:21:48 -0700 Subject: [PATCH 171/251] Create a `java_common.compile_header` API that just does the header compilation part of `java_common.compile` PiperOrigin-RevId: 921992069 Change-Id: I4dfc3671c04175e2a803427dab64a7db2a7d180c --- java/private/java_common.bzl | 28 +++ java/private/java_common_internal.bzl | 305 +++++++++++++++++++------- java/private/java_info.bzl | 2 +- 3 files changed, 253 insertions(+), 82 deletions(-) diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 174f4e6a..59ba7dfc 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl @@ -22,6 +22,7 @@ load("//java/common/rules:java_toolchain.bzl", "JavaToolchainInfo") load(":boot_class_path_info.bzl", "BootClassPathInfo") load( ":java_common_internal.bzl", + _compile_header_internal = "compile_header", _compile_internal = "compile", _run_ijar_internal = "run_ijar", ) @@ -89,6 +90,32 @@ def _compile( enable_annotation_processing = enable_annotation_processing, ) +def _compile_header( + ctx, + output, + java_toolchain, + source_jars = [], + source_files = [], + javac_opts = [], + deps = [], + plugins = [], + strict_deps = "ERROR", + bootclasspath = None, + enable_annotation_processing = True): + return _compile_header_internal( + ctx, + output = output, + java_toolchain = java_toolchain, + source_jars = source_jars, + source_files = source_files, + javac_opts = javac_opts, + deps = deps, + plugins = plugins, + strict_deps = strict_deps, + bootclasspath = bootclasspath, + enable_annotation_processing = enable_annotation_processing, + ) + def _run_ijar(actions, jar, java_toolchain, target_label = None): get_internal_java_common().check_java_toolchain_is_declared_on_rule(actions) return _run_ijar_internal( @@ -277,6 +304,7 @@ def _make_java_common(): methods = { "provider": JavaInfo, "compile": _compile, + "compile_header": _compile_header, "run_ijar": _run_ijar, "stamp_jar": _stamp_jar, "pack_sources": _pack_sources, diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl index 249b9255..30d9533c 100644 --- a/java/private/java_common_internal.bzl +++ b/java/private/java_common_internal.bzl @@ -37,6 +37,103 @@ _STRICT_DEPS_VALUES = [ "DEFAULT", # When no flag value is specified on the command line. ] +def _construct_javac_opts(ctx, java_toolchain, plugin_info, javac_opts, bootclasspath, add_exports = []): + all_javac_opts = [] # [depset[str]] + all_javac_opts.append(java_toolchain._javacopts) + all_javac_opts.append(ctx.fragments.java.default_javac_flags_depset) + all_javac_opts.append(semantics.compatible_javac_options(ctx, java_toolchain)) + + if ("com.google.devtools.build.runfiles.AutoBazelRepositoryProcessor" in + plugin_info.plugins.processor_classes.to_list()): + all_javac_opts.append(depset( + ["-Abazel.repository=" + ctx.label.repo_name], + order = "preorder", + )) + system_bootclasspath = None + for package_config in java_toolchain._package_configuration: + if package_config.matches(package_config.package_specs, ctx.label): + all_javac_opts.append(package_config.javac_opts) + if package_config.system: + if system_bootclasspath: + fail("Multiple system package configurations found for %s" % ctx.label) + system_bootclasspath = package_config.system + if not bootclasspath: + bootclasspath = system_bootclasspath + + all_javac_opts.append(depset( + ["--add-exports=%s=ALL-UNNAMED" % x for x in add_exports], + order = "preorder", + )) + + if type(javac_opts) == type([]): + # detokenize target's javacopts, it will be tokenized before compilation + all_javac_opts.append(helper.detokenize_javacopts(helper.tokenize_javacopts(ctx, javac_opts))) + elif type(javac_opts) == type(depset()): + all_javac_opts.append(javac_opts) + else: + fail("Expected javac_opts to be a list or depset, got:", type(javac_opts)) + + # we reverse the list of javacopts depsets, so that we keep the right-most set + # in case it's deduped. When this depset is flattened, we will reverse again, + # and then tokenize before passing to javac. This way, right-most javacopts will + # be retained and "win out". + return depset(order = "preorder", transitive = reversed(all_javac_opts)), bootclasspath + +def _construct_classpaths(deps, strict_deps, classpath_mode): + is_strict_mode = strict_deps != "OFF" + + direct_jars = depset() + if is_strict_mode: + direct_jars = depset(order = "preorder", transitive = [dep.compile_jars for dep in deps]) + + header_compilation_direct_deps = depset() + if is_strict_mode: + header_compilation_direct_deps = depset( + order = "preorder", + transitive = [dep.header_compilation_direct_deps for dep in deps], + ) + + compilation_classpath = depset( + order = "preorder", + transitive = [direct_jars] + [dep.transitive_compile_time_jars for dep in deps], + ) + compile_time_java_deps = depset() + if is_strict_mode and classpath_mode != "OFF": + compile_time_java_deps = depset(transitive = [dep._compile_time_java_dependencies for dep in deps]) + + return struct( + direct_jars = direct_jars, + header_compilation_direct_deps = header_compilation_direct_deps, + compilation_classpath = compilation_classpath, + compile_time_java_deps = compile_time_java_deps, + ) + +def _derive_header_compilation_outputs(ctx, base_output, suffix = ""): + if suffix: + compile_jar = _derive_output_file(ctx, base_output, name_suffix = suffix, extension = "jar") + compile_deps_proto = _derive_output_file(ctx, base_output, name_suffix = suffix, extension = "jdeps") + else: + compile_jar = base_output + compile_deps_proto = _derive_output_file(ctx, base_output, extension = "jdeps") + + # TODO: b/417791104 - remove check after a Bazel release + if ctx.fragments.java.use_header_compilation_direct_deps(): + header_compilation_jar = _derive_output_file(ctx, base_output, name_suffix = "-tjar", extension = "jar") + else: + header_compilation_jar = None + + return struct( + compile_jar = compile_jar, + header_compilation_jar = header_compilation_jar, + compile_deps_proto = compile_deps_proto, + ) + +def _validate_strict_deps(strict_deps): + strict_deps = (strict_deps or "default").upper() + if strict_deps not in _STRICT_DEPS_VALUES: + fail("Got an invalid value for strict_deps:", strict_deps, "must be one of:", _STRICT_DEPS_VALUES) + return strict_deps + def compile( ctx, output, @@ -125,54 +222,18 @@ def compile( get_internal_java_common().check_provider_instances([java_toolchain], "java_toolchain", JavaToolchainInfo) get_internal_java_common().check_provider_instances(plugins, "plugins", JavaPluginInfo) - # normalize and validate strict_deps - strict_deps = (strict_deps or "default").upper() - if strict_deps not in _STRICT_DEPS_VALUES: - fail("Got an invalid value for strict_deps:", strict_deps, "must be one of:", _STRICT_DEPS_VALUES) + strict_deps = _validate_strict_deps(strict_deps) plugin_info = merge_plugin_info_without_outputs(plugins + deps) - all_javac_opts = [] # [depset[str]] - all_javac_opts.append(java_toolchain._javacopts) - - all_javac_opts.append(ctx.fragments.java.default_javac_flags_depset) - all_javac_opts.append(semantics.compatible_javac_options(ctx, java_toolchain)) - - if ("com.google.devtools.build.runfiles.AutoBazelRepositoryProcessor" in - plugin_info.plugins.processor_classes.to_list()): - all_javac_opts.append(depset( - ["-Abazel.repository=" + ctx.label.repo_name], - order = "preorder", - )) - system_bootclasspath = None - for package_config in java_toolchain._package_configuration: - if package_config.matches(package_config.package_specs, ctx.label): - all_javac_opts.append(package_config.javac_opts) - if package_config.system: - if system_bootclasspath: - fail("Multiple system package configurations found for %s" % ctx.label) - system_bootclasspath = package_config.system - if not bootclasspath: - bootclasspath = system_bootclasspath - - all_javac_opts.append(depset( - ["--add-exports=%s=ALL-UNNAMED" % x for x in add_exports], - order = "preorder", - )) - - if type(javac_opts) == type([]): - # detokenize target's javacopts, it will be tokenized before compilation - all_javac_opts.append(helper.detokenize_javacopts(helper.tokenize_javacopts(ctx, javac_opts))) - elif type(javac_opts) == type(depset()): - all_javac_opts.append(javac_opts) - else: - fail("Expected javac_opts to be a list or depset, got:", type(javac_opts)) - - # we reverse the list of javacopts depsets, so that we keep the right-most set - # in case it's deduped. When this depset is flattened, we will reverse again, - # and then tokenize before passing to javac. This way, right-most javacopts will - # be retained and "win out". - all_javac_opts = depset(order = "preorder", transitive = reversed(all_javac_opts)) + all_javac_opts, bootclasspath = _construct_javac_opts( + ctx, + java_toolchain, + plugin_info, + javac_opts, + bootclasspath, + add_exports, + ) # Optimization: skip this if there are no annotation processors, to avoid unnecessarily # disabling the direct classpath optimization if `enable_annotation_processor = False` @@ -190,27 +251,8 @@ def compile( has_sources = source_files or source_jars has_resources = resources or resource_jars - is_strict_mode = strict_deps != "OFF" classpath_mode = ctx.fragments.java.reduce_java_classpath() - - direct_jars = depset() - if is_strict_mode: - direct_jars = depset(order = "preorder", transitive = [dep.compile_jars for dep in deps]) - - header_compilation_direct_deps = depset() - if is_strict_mode: - header_compilation_direct_deps = depset( - order = "preorder", - transitive = [dep.header_compilation_direct_deps for dep in deps], - ) - - compilation_classpath = depset( - order = "preorder", - transitive = [direct_jars] + [dep.transitive_compile_time_jars for dep in deps], - ) - compile_time_java_deps = depset() - if is_strict_mode and classpath_mode != "OFF": - compile_time_java_deps = depset(transitive = [dep._compile_time_java_dependencies for dep in deps]) + classpaths = _construct_classpaths(deps, strict_deps, classpath_mode) # create compile time jar action if not has_sources: @@ -222,14 +264,10 @@ def compile( header_compilation_jar = compile_jar compile_deps_proto = None elif _should_use_header_compilation(ctx, java_toolchain): - compile_jar = _derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jar") - - # TODO: b/417791104 - remove check after a Bazel release - if ctx.fragments.java.use_header_compilation_direct_deps(): - header_compilation_jar = _derive_output_file(ctx, output, name_suffix = "-tjar", extension = "jar") - else: - header_compilation_jar = None - compile_deps_proto = _derive_output_file(ctx, output, name_suffix = "-hjar", extension = "jdeps") + hdr_outputs = _derive_header_compilation_outputs(ctx, output, suffix = "-hjar") + compile_jar = hdr_outputs.compile_jar + header_compilation_jar = hdr_outputs.header_compilation_jar + compile_deps_proto = hdr_outputs.compile_deps_proto get_internal_java_common().create_header_compilation_action( ctx, java_toolchain, @@ -238,10 +276,10 @@ def compile( plugin_info, depset(source_files), source_jars, - compilation_classpath, - direct_jars, + classpaths.compilation_classpath, + classpaths.direct_jars, bootclasspath, - compile_time_java_deps, + classpaths.compile_time_java_deps, all_javac_opts, strict_deps, ctx.label, @@ -249,7 +287,7 @@ def compile( enable_direct_classpath, annotation_processor_additional_inputs, header_compilation_jar, - header_compilation_direct_deps, + classpaths.header_compilation_direct_deps, ) elif ctx.fragments.java.use_ijars(): compile_jar = run_ijar( @@ -282,11 +320,11 @@ def compile( output, manifest_proto, plugin_info, - compilation_classpath, - direct_jars, + classpaths.compilation_classpath, + classpaths.direct_jars, bootclasspath, depset(javabuilder_jvm_flags), - compile_time_java_deps, + classpaths.compile_time_java_deps, all_javac_opts, strict_deps, ctx.label, @@ -331,7 +369,7 @@ def compile( # needs to be flattened because the public API is a list boot_classpath = (bootclasspath.bootclasspath if bootclasspath else java_toolchain.bootclasspath).to_list(), # we only add compile time jars from deps, and not exports - compilation_classpath = compilation_classpath, + compilation_classpath = classpaths.compilation_classpath, runtime_classpath = depset( order = "preorder", direct = direct_runtime_jars, @@ -494,3 +532,108 @@ def get_runtime_classpath_for_archive(jars, excluded_jars): jars, excluded_jars, ) + +def compile_header( + ctx, + output, + java_toolchain, + source_jars = [], + source_files = [], + javac_opts = [], + deps = [], + plugins = [], + strict_deps = "ERROR", + bootclasspath = None, + injecting_rule_kind = None, + enable_annotation_processing = True): + """Compiles Java header jars from the implementation of a Starlark rule. + + Args: + ctx: (RuleContext) The rule context + output: (File) The output header jar (hjar) + java_toolchain: (JavaToolchainInfo) Toolchain to be used. Mandatory. + source_jars: ([File]) A list of the jars to be compiled. + source_files: ([File]) A list of the Java source files to be compiled. + javac_opts: ([str]|depset[str]) A list of the desired javac options. Optional. + deps: ([JavaInfo]) A list of dependencies. Optional. + plugins: ([JavaPluginInfo|JavaInfo]) A list of plugins. Optional. + strict_deps: (str) A string that specifies how to handle strict deps. Possible values: + 'OFF', 'ERROR', 'WARN' and 'DEFAULT'. + bootclasspath: (BootClassPathInfo) If present, overrides the bootclasspath associated with + the provided java_toolchain. Optional. + injecting_rule_kind: (str|None) + enable_annotation_processing: (bool) + + Returns: + (JavaInfo) + """ + get_internal_java_common().check_provider_instances([java_toolchain], "java_toolchain", JavaToolchainInfo) + get_internal_java_common().check_provider_instances(plugins, "plugins", JavaPluginInfo) + + strict_deps = _validate_strict_deps(strict_deps) + + plugin_info = merge_plugin_info_without_outputs(plugins + deps) + + all_javac_opts, bootclasspath = _construct_javac_opts( + ctx, + java_toolchain, + plugin_info, + javac_opts, + bootclasspath, + add_exports = [], + ) + + enable_direct_classpath = True + if not enable_annotation_processing and plugin_info.plugins.processor_classes: + plugin_info = disable_plugin_info_annotation_processing(plugin_info) + enable_direct_classpath = False + + classpaths = _construct_classpaths(deps, strict_deps, ctx.fragments.java.reduce_java_classpath()) + + hdr_outputs = _derive_header_compilation_outputs(ctx, output) + + get_internal_java_common().create_header_compilation_action( + ctx, + java_toolchain, + hdr_outputs.compile_jar, + hdr_outputs.compile_deps_proto, + plugin_info, + depset(source_files), + source_jars, + classpaths.compilation_classpath, + classpaths.direct_jars, + bootclasspath, + classpaths.compile_time_java_deps, + all_javac_opts, + strict_deps, + ctx.label, + injecting_rule_kind, + enable_direct_classpath, + [], # additional_inputs + hdr_outputs.header_compilation_jar, + classpaths.header_compilation_direct_deps, + ) + + return java_info_for_compilation( + output_jar = hdr_outputs.compile_jar, + compile_jar = hdr_outputs.compile_jar, + header_compilation_jar = hdr_outputs.header_compilation_jar, + source_jar = None, + generated_class_jar = None, + generated_source_jar = None, + plugin_info = plugin_info, + deps = deps, + runtime_deps = [], + exports = [], + exported_plugins = [], + compile_jdeps = hdr_outputs.compile_deps_proto, + jdeps = None, + native_headers_jar = None, + manifest_proto = None, + native_libraries = [], + neverlink = True, + add_exports = [], + add_opens = [], + direct_runtime_jars = [], + compilation_info = None, + ) diff --git a/java/private/java_info.bzl b/java/private/java_info.bzl index 19c435a2..e873ee1b 100644 --- a/java/private/java_info.bzl +++ b/java/private/java_info.bzl @@ -491,7 +491,7 @@ def java_info_for_compilation( runtime_output_jars = direct_runtime_jars, transitive_runtime_jars = transitive_runtime_jars, transitive_source_jars = depset( - direct = [source_jar], + direct = [source_jar] if source_jar else [], # only differs from the usual java_info.transitive_source_jars in the order of deps transitive = [dep.transitive_source_jars for dep in concatenated_deps.runtimedeps_exports_deps], ), From 7ed01c94b0b811415d1a35a31baab69be13977c4 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 27 May 2026 02:57:00 -0700 Subject: [PATCH 172/251] Migrate the module flag tests to Starlark The tests are removed from Bazel and added to rules_java (ignore-relnotes) PiperOrigin-RevId: 922006563 Change-Id: I7490d5219ed376c98f91e773018bad39a23d2cfc --- .bazelrc | 5 +- test/java/bazel/common/BUILD.bazel | 3 + test/java/bazel/common/java_info_tests.bzl | 67 +++++++++++++++++++ .../testutil/rules/custom_java_info_rule.bzl | 4 ++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/java/bazel/common/java_info_tests.bzl diff --git a/.bazelrc b/.bazelrc index 9db5d775..12d684fc 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,4 +16,7 @@ build --host_cxxopt=-std=c++17 # Some tests relies on dynamic libs that are not interface libs # the latter are always enabled on Windows: https://github.com/bazelbuild/bazel/blob/1f5414408467171581b6142e93f67fe730d722cf/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java#L2430 # we can't use a transition because toolchain deps exceed the default --analysis_testing_deps_limit. -test --nointerface_shared_objects \ No newline at end of file +test --nointerface_shared_objects + +# For testing add_exports/add_opens module flags behavior. +test --incompatible_java_info_merge_runtime_module_flags diff --git a/test/java/bazel/common/BUILD.bazel b/test/java/bazel/common/BUILD.bazel index 18ab4f84..c9cd0668 100644 --- a/test/java/bazel/common/BUILD.bazel +++ b/test/java/bazel/common/BUILD.bazel @@ -1,3 +1,6 @@ load(":java_common_tests.bzl", "java_common_tests") +load(":java_info_tests.bzl", "java_info_tests") java_common_tests(name = "java_common_tests") + +java_info_tests(name = "java_info_tests") diff --git a/test/java/bazel/common/java_info_tests.bzl b/test/java/bazel/common/java_info_tests.bzl new file mode 100644 index 00000000..cae1a922 --- /dev/null +++ b/test/java/bazel/common/java_info_tests.bzl @@ -0,0 +1,67 @@ +"""Tests for Bazel JavaInfo.""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_library.bzl", "java_library") +load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") +load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule") + +# We can't transition on a Starlark-semantics affecting flag, so this relies on +# --incompatible_java_info_merge_runtime_module_flags set in .bazelrc +def _test_create_java_info_with_module_flags_merge_runtime(name): + util.helper_target( + custom_java_info_rule, + name = name + "/my_starlark_rule", + output_jar = name + "/doesnotmatter.jar", + dep = [name + "/dep"], + dep_runtime = [name + "/runtime"], + dep_exports = [name + "/export"], + add_exports = ["java.base/java.lang.invoke"], + ) + util.helper_target( + java_library, + name = name + "/dep", + srcs = ["java/A.java"], + add_exports = ["java.base/java.lang"], + add_opens = ["java.base/java.lang"], + ) + + util.helper_target( + java_library, + name = name + "/runtime", + srcs = ["java/A.java"], + add_opens = ["java.base/java.util"], + ) + + util.helper_target( + java_library, + name = name + "/export", + srcs = ["java/A.java"], + add_opens = ["java.base/java.math"], + ) + + analysis_test( + name = name, + impl = _test_create_java_info_with_module_flags_merge_runtime_impl, + target = name + "/my_starlark_rule", + ) + +def _test_create_java_info_with_module_flags_merge_runtime_impl(env, target): + assert_module_info = java_info_subject.from_target(env, target).module_flags() + assert_module_info.add_exports().contains_exactly([ + "java.base/java.lang", + "java.base/java.lang.invoke", + ]).in_order() + assert_module_info.add_opens().contains_exactly([ + "java.base/java.util", + "java.base/java.math", + "java.base/java.lang", + ]).in_order() + +def java_info_tests(name): + test_suite( + name = name, + tests = [ + _test_create_java_info_with_module_flags_merge_runtime, + ], + ) diff --git a/test/java/testutil/rules/custom_java_info_rule.bzl b/test/java/testutil/rules/custom_java_info_rule.bzl index 3b61473a..e9a47918 100644 --- a/test/java/testutil/rules/custom_java_info_rule.bzl +++ b/test/java/testutil/rules/custom_java_info_rule.bzl @@ -61,6 +61,8 @@ def _impl(ctx): generated_source_jar = ctx.file.generated_source_jar, native_headers_jar = ctx.file.native_headers_jar, manifest_proto = ctx.file.manifest_proto, + add_exports = ctx.attr.add_exports, + add_opens = ctx.attr.add_opens, ), ] @@ -86,6 +88,8 @@ custom_java_info_rule = rule( "pack_sources": attr.bool(default = False), "stamp_jar": attr.bool(default = False), "compile_jar": attr.label(allow_single_file = True), + "add_exports": attr.string_list(), + "add_opens": attr.string_list(), }, toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], ) From aec8d4125cfaa2b876fe54e399b7a3523868d0f8 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 28 May 2026 02:36:43 -0700 Subject: [PATCH 173/251] Simplify launcher tests setup (ignore-relnotes) PiperOrigin-RevId: 922647628 Change-Id: Icfb5c255867440ecef0cac070e7090308ab7ae46 --- test/java/common/rules/BUILD | 6 ++ .../common_launcher_java_binary_tests.bzl | 12 ++- .../common_launcher_java_library_tests.bzl | 74 ++++++++++--------- test/java/common/rules/java_binary_tests.bzl | 17 +---- test/java/common/rules/java_library_tests.bzl | 17 +---- 5 files changed, 55 insertions(+), 71 deletions(-) diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 0f1d293c..97589249 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -1,6 +1,8 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load(":add_exports_tests.bzl", "add_exports_tests") +load(":common_launcher_java_binary_tests.bzl", "java_binary_launcher_tests") +load(":common_launcher_java_library_tests.bzl", "java_library_launcher_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") load(":java_import_tests.bzl", "java_import_tests") @@ -19,10 +21,14 @@ merge_attrs_test_suite(name = "merge_attrs_tests") java_binary_tests(name = "java_binary_tests") +java_binary_launcher_tests(name = "java_binary_launcher_tests") + java_plugin_tests(name = "java_plugin_tests") java_library_tests(name = "java_library_tests") +java_library_launcher_tests(name = "java_library_launcher_tests") + java_launcher_tests(name = "java_launcher_tests") java_import_tests(name = "java_import_tests") diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 34c6e3f5..572f27a0 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -1,6 +1,6 @@ """Parameterized tests for java_binary with --java_launcher""" -load("@rules_testing//lib:analysis_test.bzl", "analysis_test") +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") @@ -23,6 +23,10 @@ def _test_java_binary_non_executable_rule_outputs_impl(env, target): "{package}/{name}.jar", ]) -JAVA_BINARY_LAUNCHER_TESTS = [ - _test_java_binary_non_executable_rule_outputs, -] +def java_binary_launcher_tests(name): + test_suite( + name = name, + tests = [ + _test_java_binary_non_executable_rule_outputs, + ], + ) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index b1faa10b..6c6af1d0 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -2,7 +2,7 @@ load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_library.bzl", "cc_library") -load("@rules_testing//lib:analysis_test.bzl", "analysis_test") +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_import.bzl", "java_import") @@ -76,7 +76,7 @@ def _test_java_library_deps_of_genrule_are_not_on_classpath(name): util.helper_target( native.genrule, name = name + "/has_java_dep", - outs = ["foo.jar"], + outs = [name + "_foo.jar"], cmd = "echo NOT EXECUTED", tools = [name + "/root_dep"], ) @@ -99,7 +99,7 @@ def _test_java_library_deps_of_genrule_are_not_on_classpath(name): ) def _test_java_library_deps_of_genrule_are_not_on_classpath_impl(env, target): - expected_classpath = "{bin_path}/{package}/_ijar/{test_name}/has_java_dep_import/{package}/foo-ijar.jar" + expected_classpath = "{bin_path}/{package}/_ijar/{test_name}/has_java_dep_import/{package}/{test_name}_foo-ijar.jar" javac_action_subject.of(env, target, "{package}/lib{name}.jar").classpath().contains_exactly([expected_classpath]) def _test_java_library_compile_and_run_time_paths(name): @@ -1096,35 +1096,39 @@ def _test_exported_plugins_are_propagated_through_exports_impl(env, targets): "{package}/lib{test_name}/leaf_lib.jar", ).processors().contains_exactly(["com.example.process.stuff"]) -JAVA_LIBRARY_LAUNCHER_TESTS = [ - _test_java_library_rule_outputs, - _test_java_library_action_graph, - _test_java_library_deps_of_genrule_are_not_on_classpath, - _test_java_library_compile_and_run_time_paths, - _test_java_library_files_to_compile, - _test_java_library_runtime_deps_are_not_on_classpath, - _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation, - _test_java_library_propagates_native_libraries, - _test_java_library_gen_source_no_processor_names, - _test_java_library_annotation_processing_using_javacopt, - _test_java_library_javacopts_with_location_expansion, - _test_java_library_invalid_plugin, - _test_java_library_plugin_with_runtime_deps, - _test_java_library_source_jar_without_annotation_processing, - _test_java_library_source_jars_with_source_jars, - _test_java_library_should_set_bootclasspath, - _test_java_library_command_line_contains_target_label_and_rule_kind, - _test_java_library_compilation_info_provider, - _test_java_library_native_header_outputs, - _test_java_library_module_javacopts, - _test_java_library_forwarded_deps, - _test_java_library_transitive_strict_deps, - _test_java_library_emit_output_deps, - _test_java_library_deps_without_srcs, - _test_dependency_artifacts_with_exports, - _test_exports_are_indirect_not_direct, - _test_exports_runfiles, - _test_exports_collect_source_jars, - _test_exported_plugins_are_inherited, - _test_exported_plugins_are_propagated_through_exports, -] +def java_library_launcher_tests(name): + test_suite( + name = name, + tests = [ + _test_java_library_rule_outputs, + _test_java_library_action_graph, + _test_java_library_deps_of_genrule_are_not_on_classpath, + _test_java_library_compile_and_run_time_paths, + _test_java_library_files_to_compile, + _test_java_library_runtime_deps_are_not_on_classpath, + _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation, + _test_java_library_propagates_native_libraries, + _test_java_library_gen_source_no_processor_names, + _test_java_library_annotation_processing_using_javacopt, + _test_java_library_javacopts_with_location_expansion, + _test_java_library_invalid_plugin, + _test_java_library_plugin_with_runtime_deps, + _test_java_library_source_jar_without_annotation_processing, + _test_java_library_source_jars_with_source_jars, + _test_java_library_should_set_bootclasspath, + _test_java_library_command_line_contains_target_label_and_rule_kind, + _test_java_library_compilation_info_provider, + _test_java_library_native_header_outputs, + _test_java_library_module_javacopts, + _test_java_library_forwarded_deps, + _test_java_library_transitive_strict_deps, + _test_java_library_emit_output_deps, + _test_java_library_deps_without_srcs, + _test_dependency_artifacts_with_exports, + _test_exports_are_indirect_not_direct, + _test_exports_runfiles, + _test_exports_collect_source_jars, + _test_exported_plugins_are_inherited, + _test_exported_plugins_are_propagated_through_exports, + ], + ) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index f2ab5be9..b483516d 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -11,7 +11,6 @@ load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java/common:java_semantics.bzl", "semantics") load("//java/common/rules:java_helper.bzl", "helper") -load("//test/java/common/rules:common_launcher_java_binary_tests.bzl", "JAVA_BINARY_LAUNCHER_TESTS") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") @@ -408,7 +407,7 @@ def _test_one_version_check_disabled_impl(env, target): def java_binary_tests(name): test_suite( - name = "_basic_" + name, + name = name, tests = [ _test_java_binary_provides_binary_java_info, _test_stamp_conversion_does_not_override_int, @@ -421,17 +420,3 @@ def java_binary_tests(name): _test_one_version_check_disabled, ], ) - - # TODO: unset --java_launcher explicitly - test_suite( - name = "_jdk_launcher_" + name, - tests = JAVA_BINARY_LAUNCHER_TESTS, - ) - - native.test_suite( - name = name, - tests = [ - "_basic_" + name, - "_jdk_launcher_" + name, - ], - ) diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index 77980f2f..4115b121 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -9,7 +9,6 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_library.bzl", "java_library") load("//java:java_plugin.bzl", "java_plugin") load("//java/common:java_info.bzl", "JavaInfo") -load("//test/java/common/rules:common_launcher_java_library_tests.bzl", "JAVA_LIBRARY_LAUNCHER_TESTS") load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") @@ -351,7 +350,7 @@ def _test_strict_java_deps_error(name): def java_library_tests(name): test_suite( - name = "_basic_" + name, + name = name, tests = [ _test_exposes_plugins, _test_exposes_java_info, @@ -364,17 +363,3 @@ def java_library_tests(name): _test_strict_java_deps_error, ], ) - - # TODO: unset --java_launcher explicitly - test_suite( - name = "_jdk_launcher_" + name, - tests = JAVA_LIBRARY_LAUNCHER_TESTS, - ) - - native.test_suite( - name = name, - tests = [ - "_basic_" + name, - "_jdk_launcher_" + name, - ], - ) From 70844db4b45d59560c252087ffeade335172e707 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 28 May 2026 03:06:42 -0700 Subject: [PATCH 174/251] Fix test formatting and hard-coded value(s) (ignore-relnotes) PiperOrigin-RevId: 922659214 Change-Id: Ib8e6bc47538d28a0d3f03e36b96c7585f2b3f5bd --- .../common_launcher_java_library_tests.bzl | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/java/common/rules/common_launcher_java_library_tests.bzl b/test/java/common/rules/common_launcher_java_library_tests.bzl index 6c6af1d0..c66256ec 100644 --- a/test/java/common/rules/common_launcher_java_library_tests.bzl +++ b/test/java/common/rules/common_launcher_java_library_tests.bzl @@ -210,10 +210,10 @@ def _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation analysis_test( name = name, - impl = _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation_impl, config_settings = { "//command_line_option:java_header_compilation": True, }, + impl = _test_java_library_runtime_deps_are_not_on_classpath_with_header_compilation_impl, target = name + "/depends_on_runtimedep", ) @@ -291,9 +291,9 @@ def _test_java_library_invalid_plugin(name): analysis_test( name = name, + expect_failure = True, impl = _test_java_library_invalid_plugin_impl, target = name + "/lib", - expect_failure = True, ) def _test_java_library_invalid_plugin_impl(env, target): @@ -437,12 +437,12 @@ def _test_java_library_should_set_bootclasspath(name): analysis_test( name = name, - impl = _test_java_library_should_set_bootclasspath_impl, config_settings = { "//command_line_option:extra_toolchains": [ native.package_relative_label(name + "/toolchain"), ], }, + impl = _test_java_library_should_set_bootclasspath_impl, target = name + "/test_lib", ) @@ -450,7 +450,7 @@ def _test_java_library_should_set_bootclasspath_impl(env, target): javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") javac_action.bootclasspath().contains_exactly([ - "{bin_path}/{package}/test_java_library_should_set_bootclasspath/boot.jar", + "{bin_path}/{package}/{test_name}/boot.jar", ]) def _test_java_library_command_line_contains_target_label_and_rule_kind(name): @@ -620,12 +620,12 @@ def _test_java_library_compilation_info_provider(name): analysis_test( name = name, - impl = _test_java_library_compilation_info_provider_impl, config_settings = { "//command_line_option:extra_toolchains": [ native.package_relative_label(name + "/toolchain"), ], }, + impl = _test_java_library_compilation_info_provider_impl, target = name + "/test_lib", ) @@ -757,10 +757,10 @@ def _test_java_library_transitive_strict_deps(name): analysis_test( name = name, - impl = _test_java_library_transitive_strict_deps_impl, config_settings = { "//command_line_option:experimental_strict_java_deps": "ERROR", }, + impl = _test_java_library_transitive_strict_deps_impl, target = name + "/a", ) @@ -784,10 +784,10 @@ def _test_java_library_emit_output_deps(name): analysis_test( name = name, - impl = _test_java_library_emit_output_deps_impl, config_settings = { "//command_line_option:java_deps": True, }, + impl = _test_java_library_emit_output_deps_impl, targets = { "a": name + "/a", "b": name + "/b", @@ -819,9 +819,9 @@ def _test_java_library_deps_without_srcs(name): analysis_test( name = name, + expect_failure = True, impl = _test_java_library_deps_without_srcs_impl, target = name + "/a", - expect_failure = True, ) def _test_java_library_deps_without_srcs_impl(env, target): @@ -868,11 +868,11 @@ def _test_dependency_artifacts_with_exports(name): analysis_test( name = name, - impl = _test_dependency_artifacts_with_exports_impl, - target = name + "/a", config_settings = { "//command_line_option:experimental_java_classpath": "javabuilder", }, + impl = _test_dependency_artifacts_with_exports_impl, + target = name + "/a", ) def _test_dependency_artifacts_with_exports_impl(env, target): From a2f84ab0e17c659f10f2f846e2f87e8ee86f8da9 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 29 May 2026 03:47:22 -0700 Subject: [PATCH 175/251] Delete `@rules_java//java/docs` This was introduced in an effort to move the docs out of https://docs.bazel.build but never finished. In any case, requiring docs updates on every change to the rules is worse UX[^1] than regenerating them (in postsubmit). Fixes https://github.com/bazelbuild/rules_java/issues/355 PiperOrigin-RevId: 923311034 Change-Id: Ic5c2e11d6dfaf5aeaa2a79b9928c1e0f8248d8b6 --- .bazelci/presubmit.yml | 1 - java/docs/BUILD.bazel | 41 --- java/docs/rule.vm | 20 -- java/docs/rules.bzl | 22 -- java/docs/rules.md | 590 ----------------------------------------- test/BUILD.bazel | 15 -- 6 files changed, 689 deletions(-) delete mode 100644 java/docs/BUILD.bazel delete mode 100644 java/docs/rule.vm delete mode 100644 java/docs/rules.bzl delete mode 100644 java/docs/rules.md diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 6ff8d263..4e826dba 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -10,7 +10,6 @@ build_targets: &build_targets - "@remote_java_tools//:singlejar_cc_bin" # can't build @remote_java_tools_X repos for other platforms - "-//toolchains/..." - - "-//java/docs/..." build_targets_integration: &build_targets_integration - "//..." diff --git a/java/docs/BUILD.bazel b/java/docs/BUILD.bazel deleted file mode 100644 index f2b59360..00000000 --- a/java/docs/BUILD.bazel +++ /dev/null @@ -1,41 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@stardoc//stardoc:stardoc.bzl", "stardoc") - -package(default_applicable_licenses = ["@rules_java//:license"]) - -exports_files( - ["rules.md"], - visibility = ["//test:__pkg__"], -) - -bzl_library( - name = "rules_bzl", - srcs = ["rules.bzl"], - deps = [ - "//java/bazel/rules", - "//java/common/rules:toolchain_rules", - ], -) - -stardoc( - name = "rules_docs", - out = "rules_docs.out", - input = "rules.bzl", - rule_template = ":rule.vm", - symbol_names = [ - # core rules - "java_binary", - "java_import", - "java_library", - "java_plugin", - "java_test", - - # toolchain rules - "java_package_configuration", - "java_runtime", - "java_toolchain", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", - visibility = ["//test:__pkg__"], - deps = [":rules_bzl"], -) diff --git a/java/docs/rule.vm b/java/docs/rule.vm deleted file mode 100644 index dd89fdf8..00000000 --- a/java/docs/rule.vm +++ /dev/null @@ -1,20 +0,0 @@ - - -#[[##]]# ${ruleName} - -

-${util.ruleSummary($ruleName, $ruleInfo)}
-
- -${ruleInfo.docString} - -**ATTRIBUTES** - -#if (!$ruleInfo.getAttributeList().isEmpty()) - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -#foreach ($attribute in $ruleInfo.getAttributeList()) -| $attribute.name | #if(!$attribute.docString.isEmpty()) ${util.markdownCellFormat($attribute.docString)} #else - #end | ${util.attributeTypeString($attribute)} | ${util.mandatoryString($attribute)} | #if(!$attribute.defaultValue.isEmpty()) ${util.markdownCodeSpan($attribute.defaultValue)} #end | -#end -#end \ No newline at end of file diff --git a/java/docs/rules.bzl b/java/docs/rules.bzl deleted file mode 100644 index fa6c3dd8..00000000 --- a/java/docs/rules.bzl +++ /dev/null @@ -1,22 +0,0 @@ -"""Java rules""" - -load("//java/bazel/rules:bazel_java_binary.bzl", _java_binary = "java_binary") -load("//java/bazel/rules:bazel_java_import.bzl", _java_import = "java_import") -load("//java/bazel/rules:bazel_java_library.bzl", _java_library = "java_library") -load("//java/bazel/rules:bazel_java_plugin.bzl", _java_plugin = "java_plugin") -load("//java/bazel/rules:bazel_java_test.bzl", _java_test = "java_test") -load("//java/common/rules:java_package_configuration.bzl", _java_package_configuration = "java_package_configuration") -load("//java/common/rules:java_runtime.bzl", _java_runtime = "java_runtime") -load("//java/common/rules:java_toolchain.bzl", _java_toolchain = "java_toolchain") - -visibility("private") - -java_binary = _java_binary -java_import = _java_import -java_library = _java_library -java_plugin = _java_plugin -java_test = _java_test - -java_package_configuration = _java_package_configuration -java_runtime = _java_runtime -java_toolchain = _java_toolchain diff --git a/java/docs/rules.md b/java/docs/rules.md deleted file mode 100644 index b6dd015c..00000000 --- a/java/docs/rules.md +++ /dev/null @@ -1,590 +0,0 @@ - - -Java rules - - -## Rules - -- [java_binary](#java_binary) -- [java_import](#java_import) -- [java_library](#java_library) -- [java_package_configuration](#java_package_configuration) -- [java_plugin](#java_plugin) -- [java_runtime](#java_runtime) -- [java_test](#java_test) -- [java_toolchain](#java_toolchain) - - - - -## java_binary - -
-java_binary(name, deps, srcs, data, resources, add_exports, add_opens, bootclasspath,
-            classpath_resources, create_executable, deploy_env, deploy_manifest_lines, env, javacopts,
-            jvm_flags, launcher, licenses, main_class, neverlink, plugins, resource_strip_prefix,
-            runtime_deps, stamp, use_launcher, use_testrunner)
-
- -

- Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. - The wrapper shell script uses a classpath that includes, among other things, a jar file for each - library on which the binary depends. When running the wrapper shell script, any nonempty - JAVABIN environment variable will take precedence over the version specified via - Bazel's --java_runtime_version flag. -

-

- The wrapper script accepts several unique flags. Refer to - //src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt - for a list of configurable flags and environment variables accepted by the wrapper. -

- -

Implicit output targets

-
    -
  • name.jar: A Java archive, containing the class files and other - resources corresponding to the binary's direct dependencies.
  • -
  • name-src.jar: An archive containing the sources ("source - jar").
  • -
  • name_deploy.jar: A Java archive suitable for deployment (only - built if explicitly requested). -

    - Building the <name>_deploy.jar target for your rule - creates a self-contained jar file with a manifest that allows it to be run with the - java -jar command or with the wrapper script's --singlejar - option. Using the wrapper script is preferred to java -jar because it - also passes the JVM flags and the options - to load native libraries. -

    -

    - The deploy jar contains all the classes that would be found by a classloader that - searched the classpath from the binary's wrapper script from beginning to end. It also - contains the native libraries needed for dependencies. These are automatically loaded - into the JVM at runtime. -

    -

    If your target specifies a launcher - attribute, then instead of being a normal JAR file, the _deploy.jar will be a - native binary. This will contain the launcher plus any native (C++) dependencies of - your rule, all linked into a static binary. The actual jar file's bytes will be - appended to that native binary, creating a single binary blob containing both the - executable and the Java code. You can execute the resulting jar file directly - like you would execute any native binary.

    -
  • -
  • name_deploy-src.jar: An archive containing the sources - collected from the transitive closure of the target. These will match the classes in the - deploy.jar except where jars have no matching source jar.
  • -
- -

-It is good practice to use the name of the source file that is the main entry point of the -application (minus the extension). For example, if your entry point is called -Main.java, then your name could be Main. -

- -

- A deps attribute is not allowed in a java_binary rule without - srcs; such a rule requires a - main_class provided by - runtime_deps. -

- -

The following code snippet illustrates a common mistake:

- -
-
-java_binary(
-    name = "DontDoThis",
-    srcs = [
-        ...,
-        "GeneratedJavaFile.java",  # a generated .java file
-    ],
-    deps = [":generating_rule",],  # rule that generates that file
-)
-
-
- -

Do this instead:

- -
-
-java_binary(
-    name = "DoThisInstead",
-    srcs = [
-        ...,
-        ":generating_rule",
-    ],
-)
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | The list of other libraries to be linked in to the target. See general comments about deps at Typical attributes defined by most build rules. | List of labels | optional | `[]` | -| srcs | The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below.

Source files of type .java are compiled. In case of generated .java files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the outs of the generating rule. You should not list the generating rule in deps because it is a no-op.

Source files of type .srcjar are unpacked and compiled. (This is useful if you need to generate a set of .java files with a genrule.)

Rules: if the rule (typically genrule or filegroup) generates any of the files listed above, they will be used the same way as described for source files.



This argument is almost always required, except if a main_class attribute specifies a class on the runtime classpath or you specify the runtime_deps argument.

| List of labels | optional | `[]` | -| data | The list of files needed by this library at runtime. See general comments about data at Typical attributes defined by most build rules. | List of labels | optional | `[]` | -| resources | A list of data files to include in a Java jar.

Resources may be source files or generated files.



If resources are specified, they will be bundled in the jar along with the usual .class files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's standard directory layout, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <workspace root>/x/java/y/java/z, the path of the resource will be y/java/z. This heuristic cannot be overridden, however, the resource_strip_prefix attribute can be used to specify a specific alternative directory for resource files. | List of labels | optional | `[]` | -| add_exports | Allow this library to access the given module or package.

This corresponds to the javac and JVM --add-exports= flags. | List of strings | optional | `[]` | -| add_opens | Allow this library to reflectively access the given module or package.

This corresponds to the javac and JVM --add-opens= flags. | List of strings | optional | `[]` | -| bootclasspath | Restricted API, do not use! | Label | optional | `None` | -| classpath_resources | DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)

A list of resources that must be located at the root of the java tree. This attribute's only purpose is to support third-party libraries that require that their resources be found on the classpath as exactly "myconfig.xml". It is only allowed on binaries and not libraries, due to the danger of namespace conflicts.

| List of labels | optional | `[]` | -| create_executable | Deprecated, use java_single_jar instead. | Boolean | optional | `True` | -| deploy_env | A list of other java_binary targets which represent the deployment environment for this binary. Set this attribute when building a plugin which will be loaded by another java_binary.
Setting this attribute excludes all dependencies from the runtime classpath (and the deploy jar) of this binary that are shared between this binary and the targets specified in deploy_env. | List of labels | optional | `[]` | -| deploy_manifest_lines | A list of lines to add to the META-INF/manifest.mf file generated for the *_deploy.jar target. The contents of this attribute are not subject to "Make variable" substitution. | List of strings | optional | `[]` | -| env | - | Dictionary: String -> String | optional | `{}` | -| javacopts | Extra compiler options for this binary. Subject to "Make variable" substitution and Bourne shell tokenization.

These compiler options are passed to javac after the global compiler options.

| List of strings | optional | `[]` | -| jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Subject to $(location) and "Make variable" substitution, and Bourne shell tokenization.

The wrapper script for a Java binary includes a CLASSPATH definition (to find all the dependent jars) and invokes the right Java interpreter. The command line generated by the wrapper script includes the name of the main class followed by a "$@" so you can pass along other arguments after the classname. However, arguments intended for parsing by the JVM must be specified before the classname on the command line. The contents of jvm_flags are added to the wrapper script before the classname is listed.



Note that this attribute has no effect on *_deploy.jar outputs.

| List of strings | optional | `[]` | -| launcher | Specify a binary that will be used to run your Java program instead of the normal bin/java program included with the JDK. The target must be a cc_binary. Any cc_binary that implements the Java Invocation API can be specified as a value for this attribute.

By default, Bazel will use the normal JDK launcher (bin/java or java.exe).



The related --java_launcher Bazel flag affects only those java_binary and java_test targets that have not specified a launcher attribute.



Note that your native (C++, SWIG, JNI) dependencies will be built differently depending on whether you are using the JDK launcher or another launcher:



  • If you are using the normal JDK launcher (the default), native dependencies are built as a shared library named {name}_nativedeps.so, where {name} is the name attribute of this java_binary rule. Unused code is not removed by the linker in this configuration.


  • If you are using any other launcher, native (C++) dependencies are statically linked into a binary named {name}_nativedeps, where {name} is the name attribute of this java_binary rule. In this case, the linker will remove any code it thinks is unused from the resulting binary, which means any C++ code accessed only via JNI may not be linked in unless that cc_library target specifies alwayslink = True.


When using any launcher other than the default JDK launcher, the format of the *_deploy.jar output changes. See the main java_binary docs for details.

| Label | optional | `None` | -| licenses | - | List of strings | optional | `[]` | -| main_class | Name of class with main() method to use as entry point. If a rule uses this option, it does not need a srcs=[...] list. Thus, with this attribute one can make an executable from a Java library that already contains one or more main() methods.

The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from srcs) or provided by direct or transitive dependencies (through runtime_deps or deps). If the class is unavailable, the binary will fail at runtime; there is no build-time check.

| String | optional | `""` | -| neverlink | - | Boolean | optional | `False` | -| plugins | Java compiler plugins to run at compile-time. Every java_plugin specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use exported_plugins. Resources generated by the plugin will be included in the resulting jar of this rule. | List of labels | optional | `[]` | -| resource_strip_prefix | The path prefix to strip from Java resources.

If specified, this path prefix is stripped from every file in the resources attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at stuff/java/foo/bar/a.txt will be located at foo/bar/a.txt.

| String | optional | `""` | -| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both runtime_deps and deps. | List of labels | optional | `[]` | -| stamp | Whether to encode build information into the binary. Possible values:
  • stamp = 1: Always stamp the build information into the binary, even in --nostamp builds. This setting should be avoided, since it potentially kills remote caching for the binary and any downstream actions that depend on it.
  • stamp = 0: Always replace build information by constant values. This gives good build result caching.
  • stamp = -1: Embedding of build information is controlled by the --[no]stamp flag.

Stamped binaries are not rebuilt unless their dependencies change.

| Integer | optional | `-1` | -| use_launcher | Whether the binary should use a custom launcher.

If this attribute is set to false, the launcher attribute and the related --java_launcher flag will be ignored for this target. | Boolean | optional | `True` | -| use_testrunner | Use the test runner (by default com.google.testing.junit.runner.BazelTestRunner) class as the main entry point for a Java program, and provide the test class to the test runner as a value of bazel.test_suite system property.


You can use this to override the default behavior, which is to use test runner for java_test rules, and not use it for java_binary rules. It is unlikely you will want to do this. One use is for AllTest rules that are invoked by another rule (to set up a database before running the tests, for example). The AllTest rule must be declared as a java_binary, but should still use the test runner as its main entry point.

The name of a test runner class can be overridden with main_class attribute. | Boolean | optional | `False` | - - - - -## java_import - -

-java_import(name, deps, data, add_exports, add_opens, constraints, exports, jars, licenses,
-            neverlink, proguard_specs, runtime_deps, srcjar)
-
- -

- This rule allows the use of precompiled .jar files as - libraries for java_library and - java_binary rules. -

- -

Examples

- -
-
-    java_import(
-        name = "maven_model",
-        jars = [
-            "maven_model/maven-aether-provider-3.2.3.jar",
-            "maven_model/maven-model-3.2.3.jar",
-            "maven_model/maven-model-builder-3.2.3.jar",
-        ],
-    )
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | The list of other libraries to be linked in to the target. See java_library.deps. | List of labels | optional | `[]` | -| data | The list of files needed by this rule at runtime. | List of labels | optional | `[]` | -| add_exports | Allow this library to access the given module or package.

This corresponds to the javac and JVM --add-exports= flags. | List of strings | optional | `[]` | -| add_opens | Allow this library to reflectively access the given module or package.

This corresponds to the javac and JVM --add-opens= flags. | List of strings | optional | `[]` | -| constraints | Extra constraints imposed on this rule as a Java library. | List of strings | optional | `[]` | -| exports | Targets to make available to users of this rule. See java_library.exports. | List of labels | optional | `[]` | -| jars | The list of JAR files provided to Java targets that depend on this target. | List of labels | required | | -| licenses | - | List of strings | optional | `[]` | -| neverlink | Only use this library for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of libraries like this are IDE APIs for IDE plug-ins or tools.jar for anything running on a standard JDK. | Boolean | optional | `False` | -| proguard_specs | Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any android_binary target depending on this library.

The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in android_binary's proguard_specs, to ensure non-tautological merges. | List of labels | optional | `[]` | -| runtime_deps | Libraries to make available to the final binary or test at runtime only. See java_library.runtime_deps. | List of labels | optional | `[]` | -| srcjar | A JAR file that contains source code for the compiled JAR files. | Label | optional | `None` | - - - - -## java_library - -

-java_library(name, deps, srcs, data, resources, add_exports, add_opens, bootclasspath,
-             exported_plugins, exports, javabuilder_jvm_flags, javacopts, licenses, neverlink,
-             plugins, proguard_specs, resource_strip_prefix, runtime_deps)
-
- -

This rule compiles and links sources into a .jar file.

- -

Implicit outputs

-
    -
  • libname.jar: A Java archive containing the class files.
  • -
  • libname-src.jar: An archive containing the sources ("source - jar").
  • -
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | The list of libraries to link into this library. See general comments about deps at Typical attributes defined by most build rules.

The jars built by java_library rules listed in deps will be on the compile-time classpath of this rule. Furthermore the transitive closure of their deps, runtime_deps and exports will be on the runtime classpath.

By contrast, targets in the data attribute are included in the runfiles but on neither the compile-time nor runtime classpath.

| List of labels | optional | `[]` | -| srcs | The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below.

Source files of type .java are compiled. In case of generated .java files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the outs of the generating rule. You should not list the generating rule in deps because it is a no-op.

Source files of type .srcjar are unpacked and compiled. (This is useful if you need to generate a set of .java files with a genrule.)

Rules: if the rule (typically genrule or filegroup) generates any of the files listed above, they will be used the same way as described for source files.

Source files of type .properties are treated as resources.



All other files are ignored, as long as there is at least one file of a file type described above. Otherwise an error is raised.



This argument is almost always required, except if you specify the runtime_deps argument.

| List of labels | optional | `[]` | -| data | The list of files needed by this library at runtime. See general comments about data at Typical attributes defined by most build rules.

When building a java_library, Bazel doesn't put these files anywhere; if the data files are generated files then Bazel generates them. When building a test that depends on this java_library Bazel copies or links the data files into the runfiles area.

| List of labels | optional | `[]` | -| resources | A list of data files to include in a Java jar.

Resources may be source files or generated files.



If resources are specified, they will be bundled in the jar along with the usual .class files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's standard directory layout, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <workspace root>/x/java/y/java/z, the path of the resource will be y/java/z. This heuristic cannot be overridden, however, the resource_strip_prefix attribute can be used to specify a specific alternative directory for resource files. | List of labels | optional | `[]` | -| add_exports | Allow this library to access the given module or package.

This corresponds to the javac and JVM --add-exports= flags. | List of strings | optional | `[]` | -| add_opens | Allow this library to reflectively access the given module or package.

This corresponds to the javac and JVM --add-opens= flags. | List of strings | optional | `[]` | -| bootclasspath | Restricted API, do not use! | Label | optional | `None` | -| exported_plugins | The list of java_plugins (e.g. annotation processors) to export to libraries that directly depend on this library.

The specified list of java_plugins will be applied to any library which directly depends on this library, just as if that library had explicitly declared these labels in plugins.

| List of labels | optional | `[]` | -| exports | Exported libraries.

Listing rules here will make them available to parent rules, as if the parents explicitly depended on these rules. This is not true for regular (non-exported) deps.

Summary: a rule X can access the code in Y if there exists a dependency path between them that begins with a deps edge followed by zero or more exports edges. Let's see some examples to illustrate this.

Assume A depends on B and B depends on C. In this case C is a transitive dependency of A, so changing C's sources and rebuilding A will correctly rebuild everything. However A will not be able to use classes in C. To allow that, either A has to declare C in its deps, or B can make it easier for A (and anything that may depend on A) by declaring C in its (B's) exports attribute.

The closure of exported libraries is available to all direct parent rules. Take a slightly different example: A depends on B, B depends on C and D, and also exports C but not D. Now A has access to C but not to D. Now, if C and D exported some libraries, C' and D' respectively, A could only access C' but not D'.

Important: an exported rule is not a regular dependency. Sticking to the previous example, if B exports C and wants to also use C, it has to also list it in its own deps.

| List of labels | optional | `[]` | -| javabuilder_jvm_flags | Restricted API, do not use! | List of strings | optional | `[]` | -| javacopts | Extra compiler options for this library. Subject to "Make variable" substitution and Bourne shell tokenization.

These compiler options are passed to javac after the global compiler options.

| List of strings | optional | `[]` | -| licenses | - | List of strings | optional | `[]` | -| neverlink | Whether this library should only be used for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of such libraries are the IDE APIs for IDE plug-ins or tools.jar for anything running on a standard JDK.

Note that neverlink = True does not prevent the compiler from inlining material from this library into compilation targets that depend on it, as permitted by the Java Language Specification (e.g., static final constants of String or of primitive types). The preferred use case is therefore when the runtime library is identical to the compilation library.

If the runtime library differs from the compilation library then you must ensure that it differs only in places that the JLS forbids compilers to inline (and that must hold for all future versions of the JLS).

| Boolean | optional | `False` | -| plugins | Java compiler plugins to run at compile-time. Every java_plugin specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use exported_plugins. Resources generated by the plugin will be included in the resulting jar of this rule. | List of labels | optional | `[]` | -| proguard_specs | Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any android_binary target depending on this library.

The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in android_binary's proguard_specs, to ensure non-tautological merges. | List of labels | optional | `[]` | -| resource_strip_prefix | The path prefix to strip from Java resources.

If specified, this path prefix is stripped from every file in the resources attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at stuff/java/foo/bar/a.txt will be located at foo/bar/a.txt.

| String | optional | `""` | -| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both runtime_deps and deps. | List of labels | optional | `[]` | - - - - -## java_package_configuration - -
-java_package_configuration(name, data, javacopts, output_licenses, packages, system)
-
- -

-Configuration to apply to a set of packages. -Configurations can be added to -java_toolchain.javacoptss. -

- -

Example:

- -
-
-
-java_package_configuration(
-    name = "my_configuration",
-    packages = [":my_packages"],
-    javacopts = ["-Werror"],
-)
-
-package_group(
-    name = "my_packages",
-    packages = [
-        "//com/my/project/...",
-        "-//com/my/project/testing/...",
-    ],
-)
-
-java_toolchain(
-    ...,
-    package_configuration = [
-        ":my_configuration",
-    ]
-)
-
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| data | The list of files needed by this configuration at runtime. | List of labels | optional | `[]` | -| javacopts | Java compiler flags. | List of strings | optional | `[]` | -| output_licenses | - | List of strings | optional | `[]` | -| packages | The set of package_groups the configuration should be applied to. | List of labels | optional | `[]` | -| system | Corresponds to javac's --system flag. | Label | optional | `None` | - - - - -## java_plugin - -
-java_plugin(name, deps, srcs, data, resources, add_exports, add_opens, bootclasspath, generates_api,
-            javabuilder_jvm_flags, javacopts, licenses, neverlink, output_licenses, plugins,
-            processor_class, proguard_specs, resource_strip_prefix)
-
- -

- java_plugin defines plugins for the Java compiler run by Bazel. The - only supported kind of plugins are annotation processors. A java_library or - java_binary rule can run plugins by depending on them via the plugins - attribute. A java_library can also automatically export plugins to libraries that - directly depend on it using - exported_plugins. -

- -

Implicit output targets

-
    -
  • libname.jar: A Java archive.
  • -
- -

- Arguments are identical to java_library, except - for the addition of the processor_class argument. -

- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | The list of libraries to link into this library. See general comments about deps at Typical attributes defined by most build rules.

The jars built by java_library rules listed in deps will be on the compile-time classpath of this rule. Furthermore the transitive closure of their deps, runtime_deps and exports will be on the runtime classpath.

By contrast, targets in the data attribute are included in the runfiles but on neither the compile-time nor runtime classpath.

| List of labels | optional | `[]` | -| srcs | The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below.

Source files of type .java are compiled. In case of generated .java files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the outs of the generating rule. You should not list the generating rule in deps because it is a no-op.

Source files of type .srcjar are unpacked and compiled. (This is useful if you need to generate a set of .java files with a genrule.)

Rules: if the rule (typically genrule or filegroup) generates any of the files listed above, they will be used the same way as described for source files.

Source files of type .properties are treated as resources.



All other files are ignored, as long as there is at least one file of a file type described above. Otherwise an error is raised.



This argument is almost always required, except if you specify the runtime_deps argument.

| List of labels | optional | `[]` | -| data | The list of files needed by this library at runtime. See general comments about data at Typical attributes defined by most build rules.

When building a java_library, Bazel doesn't put these files anywhere; if the data files are generated files then Bazel generates them. When building a test that depends on this java_library Bazel copies or links the data files into the runfiles area.

| List of labels | optional | `[]` | -| resources | A list of data files to include in a Java jar.

Resources may be source files or generated files.



If resources are specified, they will be bundled in the jar along with the usual .class files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's standard directory layout, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <workspace root>/x/java/y/java/z, the path of the resource will be y/java/z. This heuristic cannot be overridden, however, the resource_strip_prefix attribute can be used to specify a specific alternative directory for resource files. | List of labels | optional | `[]` | -| add_exports | Allow this library to access the given module or package.

This corresponds to the javac and JVM --add-exports= flags. | List of strings | optional | `[]` | -| add_opens | Allow this library to reflectively access the given module or package.

This corresponds to the javac and JVM --add-opens= flags. | List of strings | optional | `[]` | -| bootclasspath | Restricted API, do not use! | Label | optional | `None` | -| generates_api | This attribute marks annotation processors that generate API code.

If a rule uses an API-generating annotation processor, other rules depending on it can refer to the generated code only if their compilation actions are scheduled after the generating rule. This attribute instructs Bazel to introduce scheduling constraints when --java_header_compilation is enabled.

WARNING: This attribute affects build performance, use it only if necessary.

| Boolean | optional | `False` | -| javabuilder_jvm_flags | Restricted API, do not use! | List of strings | optional | `[]` | -| javacopts | Extra compiler options for this library. Subject to "Make variable" substitution and Bourne shell tokenization.

These compiler options are passed to javac after the global compiler options.

| List of strings | optional | `[]` | -| licenses | - | List of strings | optional | `[]` | -| neverlink | Whether this library should only be used for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of such libraries are the IDE APIs for IDE plug-ins or tools.jar for anything running on a standard JDK.

Note that neverlink = True does not prevent the compiler from inlining material from this library into compilation targets that depend on it, as permitted by the Java Language Specification (e.g., static final constants of String or of primitive types). The preferred use case is therefore when the runtime library is identical to the compilation library.

If the runtime library differs from the compilation library then you must ensure that it differs only in places that the JLS forbids compilers to inline (and that must hold for all future versions of the JLS).

| Boolean | optional | `False` | -| output_licenses | - | List of strings | optional | `[]` | -| plugins | Java compiler plugins to run at compile-time. Every java_plugin specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use exported_plugins. Resources generated by the plugin will be included in the resulting jar of this rule. | List of labels | optional | `[]` | -| processor_class | The processor class is the fully qualified type of the class that the Java compiler should use as entry point to the annotation processor. If not specified, this rule will not contribute an annotation processor to the Java compiler's annotation processing, but its runtime classpath will still be included on the compiler's annotation processor path. (This is primarily intended for use by Error Prone plugins, which are loaded from the annotation processor path using java.util.ServiceLoader.) | String | optional | `""` | -| proguard_specs | Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any android_binary target depending on this library.

The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in android_binary's proguard_specs, to ensure non-tautological merges. | List of labels | optional | `[]` | -| resource_strip_prefix | The path prefix to strip from Java resources.

If specified, this path prefix is stripped from every file in the resources attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at stuff/java/foo/bar/a.txt will be located at foo/bar/a.txt.

| String | optional | `""` | - - - - -## java_runtime - -
-java_runtime(name, srcs, default_cds, hermetic_srcs, hermetic_static_libs, java, java_home,
-             lib_ct_sym, lib_modules, output_licenses, version)
-
- -

-Specifies the configuration for a Java runtime. -

- -

Example:

- -
-
-
-java_runtime(
-    name = "jdk-9-ea+153",
-    srcs = glob(["jdk9-ea+153/**"]),
-    java_home = "jdk9-ea+153",
-)
-
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| srcs | All files in the runtime. | List of labels | optional | `[]` | -| default_cds | Default CDS archive for hermetic java_runtime. When hermetic is enabled for a java_binary target and if the target does not provide its own CDS archive by specifying the classlist attribute, the java_runtime default CDS is packaged in the hermetic deploy JAR. | Label | optional | `None` | -| hermetic_srcs | Files in the runtime needed for hermetic deployments. | List of labels | optional | `[]` | -| hermetic_static_libs | The libraries that are statically linked with the launcher for hermetic deployments | List of labels | optional | `[]` | -| java | The path to the java executable. | Label | optional | `None` | -| java_home | The path to the root of the runtime. Subject to "Make" variable substitution. If this path is absolute, the rule denotes a non-hermetic Java runtime with a well-known path. In that case, the srcs and java attributes must be empty. | String | optional | `""` | -| lib_ct_sym | The lib/ct.sym file needed for compilation with --release. If not specified and there is exactly one file in srcs whose path ends with /lib/ct.sym, that file is used. | Label | optional | `None` | -| lib_modules | The lib/modules file needed for hermetic deployments. | Label | optional | `None` | -| output_licenses | - | List of strings | optional | `[]` | -| version | The feature version of the Java runtime. I.e., the integer returned by Runtime.version().feature(). | Integer | optional | `0` | - - - - -## java_test - -
-java_test(name, deps, srcs, data, resources, add_exports, add_opens, bootclasspath,
-          classpath_resources, create_executable, deploy_manifest_lines, env, env_inherit, javacopts,
-          jvm_flags, launcher, licenses, main_class, neverlink, plugins, resource_strip_prefix,
-          runtime_deps, stamp, test_class, use_launcher, use_testrunner)
-
- -

-A java_test() rule compiles a Java test. A test is a binary wrapper around your -test code. The test runner's main method is invoked instead of the main class being compiled. -

- -

Implicit output targets

-
    -
  • name.jar: A Java archive.
  • -
  • name_deploy.jar: A Java archive suitable - for deployment. (Only built if explicitly requested.) See the description of the - name_deploy.jar output from - java_binary for more details.
  • -
- -

-See the section on java_binary() arguments. This rule also -supports all attributes common -to all test rules (*_test). -

- -

Examples

- -
-
-
-java_library(
-    name = "tests",
-    srcs = glob(["*.java"]),
-    deps = [
-        "//java/com/foo/base:testResources",
-        "//java/com/foo/testing/util",
-    ],
-)
-
-java_test(
-    name = "AllTests",
-    size = "small",
-    runtime_deps = [
-        ":tests",
-        "//util/mysql",
-    ],
-)
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | The list of other libraries to be linked in to the target. See general comments about deps at Typical attributes defined by most build rules. | List of labels | optional | `[]` | -| srcs | The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below.

Source files of type .java are compiled. In case of generated .java files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the outs of the generating rule. You should not list the generating rule in deps because it is a no-op.

Source files of type .srcjar are unpacked and compiled. (This is useful if you need to generate a set of .java files with a genrule.)

Rules: if the rule (typically genrule or filegroup) generates any of the files listed above, they will be used the same way as described for source files.



This argument is almost always required, except if a main_class attribute specifies a class on the runtime classpath or you specify the runtime_deps argument.

| List of labels | optional | `[]` | -| data | The list of files needed by this library at runtime. See general comments about data at Typical attributes defined by most build rules. | List of labels | optional | `[]` | -| resources | A list of data files to include in a Java jar.

Resources may be source files or generated files.



If resources are specified, they will be bundled in the jar along with the usual .class files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's standard directory layout, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <workspace root>/x/java/y/java/z, the path of the resource will be y/java/z. This heuristic cannot be overridden, however, the resource_strip_prefix attribute can be used to specify a specific alternative directory for resource files. | List of labels | optional | `[]` | -| add_exports | Allow this library to access the given module or package.

This corresponds to the javac and JVM --add-exports= flags. | List of strings | optional | `[]` | -| add_opens | Allow this library to reflectively access the given module or package.

This corresponds to the javac and JVM --add-opens= flags. | List of strings | optional | `[]` | -| bootclasspath | Restricted API, do not use! | Label | optional | `None` | -| classpath_resources | DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)

A list of resources that must be located at the root of the java tree. This attribute's only purpose is to support third-party libraries that require that their resources be found on the classpath as exactly "myconfig.xml". It is only allowed on binaries and not libraries, due to the danger of namespace conflicts.

| List of labels | optional | `[]` | -| create_executable | Deprecated, use java_single_jar instead. | Boolean | optional | `True` | -| deploy_manifest_lines | A list of lines to add to the META-INF/manifest.mf file generated for the *_deploy.jar target. The contents of this attribute are not subject to "Make variable" substitution. | List of strings | optional | `[]` | -| env | - | Dictionary: String -> String | optional | `{}` | -| env_inherit | - | List of strings | optional | `[]` | -| javacopts | Extra compiler options for this binary. Subject to "Make variable" substitution and Bourne shell tokenization.

These compiler options are passed to javac after the global compiler options.

| List of strings | optional | `[]` | -| jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Subject to $(location) and "Make variable" substitution, and Bourne shell tokenization.

The wrapper script for a Java binary includes a CLASSPATH definition (to find all the dependent jars) and invokes the right Java interpreter. The command line generated by the wrapper script includes the name of the main class followed by a "$@" so you can pass along other arguments after the classname. However, arguments intended for parsing by the JVM must be specified before the classname on the command line. The contents of jvm_flags are added to the wrapper script before the classname is listed.



Note that this attribute has no effect on *_deploy.jar outputs.

| List of strings | optional | `[]` | -| launcher | Specify a binary that will be used to run your Java program instead of the normal bin/java program included with the JDK. The target must be a cc_binary. Any cc_binary that implements the Java Invocation API can be specified as a value for this attribute.

By default, Bazel will use the normal JDK launcher (bin/java or java.exe).



The related --java_launcher Bazel flag affects only those java_binary and java_test targets that have not specified a launcher attribute.



Note that your native (C++, SWIG, JNI) dependencies will be built differently depending on whether you are using the JDK launcher or another launcher:



  • If you are using the normal JDK launcher (the default), native dependencies are built as a shared library named {name}_nativedeps.so, where {name} is the name attribute of this java_binary rule. Unused code is not removed by the linker in this configuration.


  • If you are using any other launcher, native (C++) dependencies are statically linked into a binary named {name}_nativedeps, where {name} is the name attribute of this java_binary rule. In this case, the linker will remove any code it thinks is unused from the resulting binary, which means any C++ code accessed only via JNI may not be linked in unless that cc_library target specifies alwayslink = True.


When using any launcher other than the default JDK launcher, the format of the *_deploy.jar output changes. See the main java_binary docs for details.

| Label | optional | `None` | -| licenses | - | List of strings | optional | `[]` | -| main_class | Name of class with main() method to use as entry point. If a rule uses this option, it does not need a srcs=[...] list. Thus, with this attribute one can make an executable from a Java library that already contains one or more main() methods.

The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from srcs) or provided by direct or transitive dependencies (through runtime_deps or deps). If the class is unavailable, the binary will fail at runtime; there is no build-time check.

| String | optional | `""` | -| neverlink | - | Boolean | optional | `False` | -| plugins | Java compiler plugins to run at compile-time. Every java_plugin specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use exported_plugins. Resources generated by the plugin will be included in the resulting jar of this rule. | List of labels | optional | `[]` | -| resource_strip_prefix | The path prefix to strip from Java resources.

If specified, this path prefix is stripped from every file in the resources attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at stuff/java/foo/bar/a.txt will be located at foo/bar/a.txt.

| String | optional | `""` | -| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both runtime_deps and deps. | List of labels | optional | `[]` | -| stamp | Whether to encode build information into the binary. Possible values:
  • stamp = 1: Always stamp the build information into the binary, even in --nostamp builds. This setting should be avoided, since it potentially kills remote caching for the binary and any downstream actions that depend on it.
  • stamp = 0: Always replace build information by constant values. This gives good build result caching.
  • stamp = -1: Embedding of build information is controlled by the --[no]stamp flag.

Stamped binaries are not rebuilt unless their dependencies change.

| Integer | optional | `0` | -| test_class | The Java class to be loaded by the test runner.

By default, if this argument is not defined then the legacy mode is used and the test arguments are used instead. Set the --nolegacy_bazel_java_test flag to not fallback on the first argument.

This attribute specifies the name of a Java class to be run by this test. It is rare to need to set this. If this argument is omitted, it will be inferred using the target's name and its source-root-relative path. If the test is located outside a known source root, Bazel will report an error if test_class is unset.

For JUnit3, the test class needs to either be a subclass of junit.framework.TestCase or it needs to have a public static suite() method that returns a junit.framework.Test (or a subclass of Test). For JUnit4, the class needs to be annotated with org.junit.runner.RunWith.

This attribute allows several java_test rules to share the same Test (TestCase, TestSuite, ...). Typically additional information is passed to it (e.g. via jvm_flags=['-Dkey=value']) so that its behavior differs in each case, such as running a different subset of the tests. This attribute also enables the use of Java tests outside the javatests tree.

| String | optional | `""` | -| use_launcher | Whether the binary should use a custom launcher.

If this attribute is set to false, the launcher attribute and the related --java_launcher flag will be ignored for this target. | Boolean | optional | `True` | -| use_testrunner | Use the test runner (by default com.google.testing.junit.runner.BazelTestRunner) class as the main entry point for a Java program, and provide the test class to the test runner as a value of bazel.test_suite system property.


You can use this to override the default behavior, which is to use test runner for java_test rules, and not use it for java_binary rules. It is unlikely you will want to do this. One use is for AllTest rules that are invoked by another rule (to set up a database before running the tests, for example). The AllTest rule must be declared as a java_binary, but should still use the test runner as its main entry point.

The name of a test runner class can be overridden with main_class attribute. | Boolean | optional | `True` | - - - - -## java_toolchain - -

-java_toolchain(name, android_lint_data, android_lint_jvm_opts, android_lint_opts,
-               android_lint_package_configuration, android_lint_runner, bootclasspath,
-               compatible_javacopts, deps_checker, forcibly_disable_header_compilation, genclass,
-               header_compiler, header_compiler_builtin_processors, header_compiler_direct, ijar,
-               jacocorunner, java_runtime, javabuilder, javabuilder_data, javabuilder_jvm_opts,
-               javac_supports_multiplex_workers, javac_supports_worker_cancellation,
-               javac_supports_worker_multiplex_sandboxing, javac_supports_workers, javacopts,
-               jspecify_implicit_deps, jspecify_javacopts, jspecify_packages, jspecify_processor,
-               jspecify_processor_class, jspecify_stubs, jvm_opts, licenses, misc, oneversion,
-               oneversion_allowlist, oneversion_allowlist_for_tests, oneversion_whitelist,
-               package_configuration, proguard_allowlister, reduced_classpath_incompatible_processors,
-               singlejar, source_version, target_version, timezone_data, tools, turbine_data,
-               turbine_jvm_opts, xlint)
-
- -

-Specifies the configuration for the Java compiler. Which toolchain to be used can be changed through -the --java_toolchain argument. Normally you should not write those kind of rules unless you want to -tune your Java compiler. -

- -

Examples

- -

A simple example would be: -

- -
-
-
-java_toolchain(
-    name = "toolchain",
-    source_version = "7",
-    target_version = "7",
-    bootclasspath = ["//tools/jdk:bootclasspath"],
-    xlint = [ "classfile", "divzero", "empty", "options", "path" ],
-    javacopts = [ "-g" ],
-    javabuilder = ":JavaBuilder_deploy.jar",
-)
-
-
- -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| android_lint_data | Labels of tools available for label-expansion in android_lint_jvm_opts. | List of labels | optional | `[]` | -| android_lint_jvm_opts | The list of arguments for the JVM when invoking Android Lint. | List of strings | optional | `[]` | -| android_lint_opts | The list of Android Lint arguments. | List of strings | optional | `[]` | -| android_lint_package_configuration | Android Lint Configuration that should be applied to the specified package groups. | List of labels | optional | `[]` | -| android_lint_runner | Label of the Android Lint runner, if any. | Label | optional | `None` | -| bootclasspath | The Java target bootclasspath entries. Corresponds to javac's -bootclasspath flag. | List of labels | optional | `[]` | -| compatible_javacopts | Internal API, do not use! | Dictionary: String -> List of strings | optional | `{}` | -| deps_checker | Label of the ImportDepsChecker deploy jar. | Label | optional | `None` | -| forcibly_disable_header_compilation | Overrides --java_header_compilation to disable header compilation on platforms that do not support it, e.g. JDK 7 Bazel. | Boolean | optional | `False` | -| genclass | Label of the GenClass deploy jar. | Label | optional | `None` | -| header_compiler | Label of the header compiler. Required if --java_header_compilation is enabled. | Label | optional | `None` | -| header_compiler_builtin_processors | Internal API, do not use! | List of strings | optional | `[]` | -| header_compiler_direct | Optional label of the header compiler to use for direct classpath actions that do not include any API-generating annotation processors.

This tool does not support annotation processing. | Label | optional | `None` | -| ijar | Label of the ijar executable. | Label | optional | `None` | -| jacocorunner | Label of the JacocoCoverageRunner deploy jar. | Label | optional | `None` | -| java_runtime | The java_runtime to use with this toolchain. It defaults to java_runtime in execution configuration. | Label | optional | `None` | -| javabuilder | Label of the JavaBuilder deploy jar. | Label | optional | `None` | -| javabuilder_data | Labels of data available for label-expansion in javabuilder_jvm_opts. | List of labels | optional | `[]` | -| javabuilder_jvm_opts | The list of arguments for the JVM when invoking JavaBuilder. | List of strings | optional | `[]` | -| javac_supports_multiplex_workers | True if JavaBuilder supports running as a multiplex persistent worker, false if it doesn't. | Boolean | optional | `True` | -| javac_supports_worker_cancellation | True if JavaBuilder supports cancellation of persistent workers, false if it doesn't. | Boolean | optional | `True` | -| javac_supports_worker_multiplex_sandboxing | True if JavaBuilder supports running as a multiplex persistent worker with sandboxing, false if it doesn't. | Boolean | optional | `False` | -| javac_supports_workers | True if JavaBuilder supports running as a persistent worker, false if it doesn't. | Boolean | optional | `True` | -| javacopts | The list of extra arguments for the Java compiler. Please refer to the Java compiler documentation for the extensive list of possible Java compiler flags. | List of strings | optional | `[]` | -| jspecify_implicit_deps | Experimental, do not use! | Label | optional | `None` | -| jspecify_javacopts | Experimental, do not use! | List of strings | optional | `[]` | -| jspecify_packages | Experimental, do not use! | List of labels | optional | `[]` | -| jspecify_processor | Experimental, do not use! | Label | optional | `None` | -| jspecify_processor_class | Experimental, do not use! | String | optional | `""` | -| jspecify_stubs | Experimental, do not use! | List of labels | optional | `[]` | -| jvm_opts | The list of arguments for the JVM when invoking the Java compiler. Please refer to the Java virtual machine documentation for the extensive list of possible flags for this option. | List of strings | optional | `[]` | -| licenses | - | List of strings | optional | `[]` | -| misc | Deprecated: use javacopts instead | List of strings | optional | `[]` | -| oneversion | Label of the one-version enforcement binary. | Label | optional | `None` | -| oneversion_allowlist | Label of the one-version allowlist. | Label | optional | `None` | -| oneversion_allowlist_for_tests | Label of the one-version allowlist for tests. | Label | optional | `None` | -| oneversion_whitelist | Deprecated: use oneversion_allowlist instead | Label | optional | `None` | -| package_configuration | Configuration that should be applied to the specified package groups. | List of labels | optional | `[]` | -| proguard_allowlister | Label of the Proguard allowlister. | Label | optional | `"@bazel_tools//tools/jdk:proguard_whitelister"` | -| reduced_classpath_incompatible_processors | Internal API, do not use! | List of strings | optional | `[]` | -| singlejar | Label of the SingleJar deploy jar. | Label | optional | `None` | -| source_version | The Java source version (e.g., '6' or '7'). It specifies which set of code structures are allowed in the Java source code. | String | optional | `""` | -| target_version | The Java target version (e.g., '6' or '7'). It specifies for which Java runtime the class should be build. | String | optional | `""` | -| timezone_data | Label of a resource jar containing timezone data. If set, the timezone data is added as an implicitly runtime dependency of all java_binary rules. | Label | optional | `None` | -| tools | Labels of tools available for label-expansion in jvm_opts. | List of labels | optional | `[]` | -| turbine_data | Labels of data available for label-expansion in turbine_jvm_opts. | List of labels | optional | `[]` | -| turbine_jvm_opts | The list of arguments for the JVM when invoking turbine. | List of strings | optional | `[]` | -| xlint | The list of warning to add or removes from default list. Precedes it with a dash to removes it. Please see the Javac documentation on the -Xlint options for more information. | List of strings | optional | `[]` | - - diff --git a/test/BUILD.bazel b/test/BUILD.bazel index fdc241fb..9d133ce7 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("@rules_shell//shell:sh_test.bzl", "sh_test") load("//java:repositories.bzl", "JAVA_TOOLS_CONFIG", "REMOTE_JDK_CONFIGS") load(":check_remotejdk_configs_match.bzl", "validate_configs") @@ -62,20 +61,6 @@ sh_test( tags = ["manual"], # explicitly tested only on Linux ) -diff_test( - name = "docs_up_to_date_test", - failure_message = """ - Docs are no longer up to date. Regenerate them by running: - - bazel build //java/docs:rules_docs && \ - cp bazel-bin/java/docs/rules_docs.out java/docs/rules.md - """, - file1 = "//java/docs:rules.md", - file2 = "//java/docs:rules_docs", - # TODO: b/369123329 - re-enable docs after moving them out of https://bazel.build/reference/be/java - tags = ["manual"], -) - validate_configs() starlark_doc_extract( From 68b16bd1a29ec88687eb07145630ee8739c93f89 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 2 Jun 2026 01:09:10 -0700 Subject: [PATCH 176/251] Add test that `java_binary` has no launcher dep if `create_executable = False` (ignore-relnotes) PiperOrigin-RevId: 925182502 Change-Id: I134f0b495815f30d6161320d108180c0a5894463 --- test/java/common/rules/java_binary_tests.bzl | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index b483516d..d4699fa0 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -405,6 +405,29 @@ def _test_one_version_check_disabled_impl(env, target): action_mnemonics = [a.mnemonic for a in env.expect.that_target(target).actual.actions] env.expect.that_collection(action_mnemonics).not_contains("JavaOneVersion") +def _test_java_binary_no_launcher_dep_if_not_executable(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["bin.java"], + create_executable = False, + ) + util.helper_target( + cc_binary, + name = name + "/broken", + srcs = ["launcher.cc"], + deps = [":doesnotexist"], + ) + + analysis_test( + name = name, + impl = lambda *args, **kwargs: None, # no error: good + target = name + "/bin", + config_settings = { + "//command_line_option:java_launcher": Label(name + "/broken"), + }, + ) + def java_binary_tests(name): test_suite( name = name, @@ -418,5 +441,6 @@ def java_binary_tests(name): _test_one_version_check_action, _test_one_version_check_violations_allowed, _test_one_version_check_disabled, + _test_java_binary_no_launcher_dep_if_not_executable, ], ) From 2f574645ab441031629bb286e1c4446031c12223 Mon Sep 17 00:00:00 2001 From: zhaixiaojuan Date: Wed, 3 Jun 2026 02:27:03 -0700 Subject: [PATCH 177/251] Simplify toolchain config for linux (#357) Motivation is to add loongarch64 support Closes #357 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/357 from zhaixiaojuan:master 9cf1278223d5e518cbe94dcb17b394b85e065b9c PiperOrigin-RevId: 925885213 Change-Id: Id14b277152d7d962bd3f8776c5dad0076819f9ad --- toolchains/BUILD | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/toolchains/BUILD b/toolchains/BUILD index 0f3ef2bf..007b6101 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -140,12 +140,7 @@ cc_library( hdrs = [":jni_header"] + select({ "@bazel_tools//src/conditions:darwin": [":jni_md_header-darwin"], "@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"], - "@bazel_tools//src/conditions:linux_aarch64": [":jni_md_header-linux"], - "@bazel_tools//src/conditions:linux_mips64": [":jni_md_header-linux"], - "@bazel_tools//src/conditions:linux_ppc64le": [":jni_md_header-linux"], - "@bazel_tools//src/conditions:linux_riscv64": [":jni_md_header-linux"], - "@bazel_tools//src/conditions:linux_s390x": [":jni_md_header-linux"], - "@bazel_tools//src/conditions:linux_x86_64": [":jni_md_header-linux"], + "@bazel_tools//src/conditions:linux": [":jni_md_header-linux"], "@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"], "@bazel_tools//src/conditions:windows": [":jni_md_header-windows"], "//conditions:default": [], @@ -153,12 +148,7 @@ cc_library( includes = ["include"] + select({ "@bazel_tools//src/conditions:darwin": ["include/darwin"], "@bazel_tools//src/conditions:freebsd": ["include/freebsd"], - "@bazel_tools//src/conditions:linux_aarch64": ["include/linux"], - "@bazel_tools//src/conditions:linux_mips64": ["include/linux"], - "@bazel_tools//src/conditions:linux_ppc64le": ["include/linux"], - "@bazel_tools//src/conditions:linux_riscv64": ["include/linux"], - "@bazel_tools//src/conditions:linux_s390x": ["include/linux"], - "@bazel_tools//src/conditions:linux_x86_64": ["include/linux"], + "@bazel_tools//src/conditions:linux": ["include/linux"], "@bazel_tools//src/conditions:openbsd": ["include/openbsd"], "@bazel_tools//src/conditions:windows": ["include/win32"], "//conditions:default": [], From 923e7662c02fa0b27f1e8cc8dbfbbd62fc920825 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 3 Jun 2026 03:05:18 -0700 Subject: [PATCH 178/251] Cleanup obsolete TODO Was done in https://github.com/bazelbuild/rules_java/pull/357 (ignore-relnotes) PiperOrigin-RevId: 925901106 Change-Id: I132bca7684b3edc42e5d82acdf4fa8826d2f7590 --- toolchains/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/toolchains/BUILD b/toolchains/BUILD index 007b6101..30b78e59 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -133,8 +133,6 @@ java_runtime_files( # # See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for # an example of using Bazel to build a Java program that calls a C function. -# -# TODO(ilist): use //src:condition:linux when released in Bazel cc_library( name = "jni", hdrs = [":jni_header"] + select({ From 1f215f8ca1c459e4c564f6c9b3f88d1cfa7a113a Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 11 Jun 2026 02:01:33 -0700 Subject: [PATCH 179/251] Improve the artifact closure API for tests (ignore-relnotes) PiperOrigin-RevId: 930378334 Change-Id: Ifb3689c9a388151707b164a46cc9d64bc1817380 --- MODULE.bazel | 6 +++--- test/java/common/java_common_tests.bzl | 13 ++++-------- test/java/testutil/artifact_closure.bzl | 27 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 38405ca6..a088efe7 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -124,9 +124,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-WYc72jM8jNK3m45vjWlmN6NB+95f6HAHnTkRaSaNisE=", - strip_prefix = "rules_testing-04a1219ee516ccdf3ffadfe3b28e5c634c9b90e1", - urls = ["https://github.com/bazelbuild/rules_testing/archive/04a1219ee516ccdf3ffadfe3b28e5c634c9b90e1.tar.gz"], + integrity = "sha256-ZmrwZSmn3NkEj0MOnix9oSMzPXJWbuJbCCbOM1C03QQ=", + strip_prefix = "rules_testing-ff65fc8b7f1b7c37de71d781601ff40288de80f2", + urls = ["https://github.com/bazelbuild/rules_testing/archive/ff65fc8b7f1b7c37de71d781601ff40288de80f2.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index 756e3a42..0a3b257c 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -725,15 +725,10 @@ def _test_compile_neverlink(name): ) def _test_compile_neverlink_impl(env, target): - java_source_basenames = [ - f.basename - for f in artifact_closure.of_target(target) - if f.extension == "java" - ] - env.expect.that_collection(java_source_basenames).contains_exactly([ - "Plugin.java", - "Dependency.java", - "EclipseDependency.java", + artifact_closure.of_target(env, target, extensions = ["java"]).contains_exactly([ + "{package}/Plugin.java", + "{package}/Dependency.java", + "{package}/EclipseDependency.java", ]) jars_in_runfiles = [ f.basename diff --git a/test/java/testutil/artifact_closure.bzl b/test/java/testutil/artifact_closure.bzl index 129b5884..b7141f0f 100644 --- a/test/java/testutil/artifact_closure.bzl +++ b/test/java/testutil/artifact_closure.bzl @@ -1,8 +1,10 @@ """Helper for computing the artifact closure of a target""" +load("@rules_testing//lib:truth.bzl", "subjects") + # TODO: consider upstreaming this to @rules_testing -def _of_target(target): +def _compute(target): to_process = target[DefaultInfo].files.to_list() if _ArtifactActionMapInfo not in target: fail("Did you forget to add the aspect to analysis_test(extra_target_under_test_aspects = )?") @@ -49,6 +51,29 @@ def _aspect_impl(target, ctx): _aspect = aspect(_aspect_impl, attr_aspects = ["*"]) +def _of_target(env, target, as_paths = True, extensions = None): + meta = env.expect.meta.derive(format_str_kwargs = { + "name": target.label.name, + "package": target.label.package, + }) + result = subjects.collection( + _compute(target), + meta = meta, + container_name = "artifact clousre of {}".format(target.label), + format = True, + ) + if extensions: + result = result.transform( + filter = lambda f: f.extension in extensions, + desc = "with extensions: {exts}".format(exts = extensions), + ) + if as_paths: + result = result.transform( + desc = "short_path", + map_each = lambda f: f.short_path, + ) + return result + artifact_closure = struct( aspect = _aspect, of_target = _of_target, From 35e8391a1c37dd5941ba594a01dcb08d3985cbd8 Mon Sep 17 00:00:00 2001 From: mgalindo-sc <161385164+mgalindo-sc@users.noreply.github.com> Date: Fri, 12 Jun 2026 10:44:46 -0700 Subject: [PATCH 180/251] Do not percent-encode '+' in classpath-jar manifest Class-Path entries (#358) Add '+' to the allowed character class so it passes through literally. The java stub template packs over-long classpaths into a classpath jar whose manifest Class-Path entries percent-encode any character outside [-_.~/a-zA-Z0-9]. Bzlmod canonical repository names put '+' into every external-repo classpath entry, so those entries now contain "%2b" sequences. '+' is a valid URI path character and needs no encoding, and the "%2b" breaks consumers that pass classpath URLs through printf-style formatting Closes #358 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/358 from mgalindo-sc:patch-1 367ccce6a08bb163cfde47ebe44fcdf34593f463 PiperOrigin-RevId: 931225696 Change-Id: I3c4e215afc4c67e25e48485cd58d0c2fe2dcd74c --- java/bazel/rules/java_stub_template.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/bazel/rules/java_stub_template.txt b/java/bazel/rules/java_stub_template.txt index 115b46e6..8dddd4a3 100644 --- a/java/bazel/rules/java_stub_template.txt +++ b/java/bazel/rules/java_stub_template.txt @@ -315,14 +315,14 @@ function create_classpath_jar() { for path in ${CLASSPATH}; do # Loop through the characters of the path and convert characters that are # not alphanumeric nor -_.~/ to their 2-digit hexadecimal representation - if [[ ! $path =~ ^[-_.~/a-zA-Z0-9]*$ ]]; then + if [[ ! $path =~ ^[-_.~/a-zA-Z0-9+]*$ ]]; then local i c buff local converted_path="" for ((i=0; i<${#path}; i++)); do c=${path:$i:1} case ${c} in - [-_.~/a-zA-Z0-9] ) buff=${c} ;; + [-_.~/a-zA-Z0-9+] ) buff=${c} ;; * ) printf -v buff '%%%02x' "'$c'" esac converted_path+="${buff}" From 57dc3a25c9269707943ec6a97f635d88b216be71 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 17 Jun 2026 04:02:02 -0700 Subject: [PATCH 181/251] Add a test for `java_binary` without sources. PiperOrigin-RevId: 933630740 Change-Id: Ibb7112caefa50b3ba8b4425d294781b978549a4f --- test/bazel/BUILD.bazel | 11 +++++++++++ test/java/bazel/rules/java_binary_tests.bzl | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/bazel/BUILD.bazel diff --git a/test/bazel/BUILD.bazel b/test/bazel/BUILD.bazel new file mode 100644 index 00000000..50fff509 --- /dev/null +++ b/test/bazel/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") + +# Used in test/java/bazel/rules/java_binary_tests.bzl%_test_java_binary_empty_srcs +util.helper_target( + java_binary, + name = "bin_without_srcs", + visibility = [ + "//test/java/bazel/rules:__pkg__", + ], +) diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 8c385046..8436e0e6 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -1,6 +1,7 @@ """Tests for the Bazel java_binary rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") @@ -118,6 +119,19 @@ def _test_java_binary_resource_strip_prefix_impl(env, target): ("--resources", "{package}/path/to/strip/bar.props:bar.props"), ]) +def _test_java_binary_empty_srcs(name): + analysis_test( + name = name, + impl = _test_java_binary_empty_srcs_impl, + target = "//test/bazel:bin_without_srcs", # need a target not under a `/java/` segment + expect_failure = True, + ) + +def _test_java_binary_empty_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate(matching.str_matches( + "need at least one of 'main_class' or Java source files", + )) + def java_binary_tests(name): test_suite( name = name, @@ -126,5 +140,6 @@ def java_binary_tests(name): _test_java_binary_javacopts_make_variable_expansion, _test_java_binary_javacopts_location_expansion, _test_java_binary_resource_strip_prefix, + _test_java_binary_empty_srcs, ], ) From 26b895ad4753fdd2206919fab5e6a055fee9ae0d Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 18 Jun 2026 01:58:19 -0700 Subject: [PATCH 182/251] Refactor test suite property name for testing (ignore-relnotes) PiperOrigin-RevId: 934207591 Change-Id: I89c130d302f1c9c710a2c9025cee482d5a3eef09 --- java/bazel/rules/bazel_java_binary.bzl | 5 ++++- java/common/java_semantics.bzl | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl index 4ee9c881..716cde19 100644 --- a/java/bazel/rules/bazel_java_binary.bzl +++ b/java/bazel/rules/bazel_java_binary.bzl @@ -87,7 +87,10 @@ def bazel_base_binary_impl(ctx, is_test_rule_class): "rule or add a 'test_class' attribute.") jvm_flags.extend([ "-ea", - "-Dbazel.test_suite=" + helper.shell_escape(test_class), + "-D{prop_name}={prop_value}".format( + prop_name = semantics.TEST_SUITE_PROPERTY_NAME, + prop_value = helper.shell_escape(test_class), + ), ]) java_attrs = providers["InternalDeployJarInfo"].java_attrs diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 919553e9..c85ec048 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -128,4 +128,5 @@ semantics = struct( update_args_for_import_deps = _update_args_for_import_deps, expand_javacopts_make_variables = True, java_toolchain_supports_one_version = _bazel_version_ge("8.0.0"), # can be dropped once we no longer support Bazel 7 + TEST_SUITE_PROPERTY_NAME = "bazel.test_suite", ) From d999e96fd201451adbd3dbb22c9272d74c0c6e9c Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 19 Jun 2026 01:00:04 -0700 Subject: [PATCH 183/251] Add a test for `java_binary` without `/java/` in the package path PiperOrigin-RevId: 934781490 Change-Id: Ia341dbbcfb6a15b41f3888d9877f08e83f0b82c6 --- test/java/common/rules/java_binary_tests.bzl | 15 ++++++++++++++ test/testdata/BUILD | 21 ++++++++++++++++++++ test/testdata/BUILD.bazel | 9 --------- 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/testdata/BUILD delete mode 100644 test/testdata/BUILD.bazel diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index d4699fa0..05e7e8a6 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -428,6 +428,20 @@ def _test_java_binary_no_launcher_dep_if_not_executable(name): }, ) +# regression test for #887069 +def _test_java_binary_java_package(name): + analysis_test( + name = name, + impl = _test_java_binary_java_package_impl, + target = "//test/testdata:non_java", + expect_failure = True, + ) + +def _test_java_binary_java_package_impl(env, target): + env.expect.that_target(target).failures().contains_predicate(matching.str_matches( + "main_class was not provided and cannot be inferred", + )) + def java_binary_tests(name): test_suite( name = name, @@ -442,5 +456,6 @@ def java_binary_tests(name): _test_one_version_check_violations_allowed, _test_one_version_check_disabled, _test_java_binary_no_launcher_dep_if_not_executable, + _test_java_binary_java_package, ], ) diff --git a/test/testdata/BUILD b/test/testdata/BUILD new file mode 100644 index 00000000..2de4a356 --- /dev/null +++ b/test/testdata/BUILD @@ -0,0 +1,21 @@ +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") + +package(default_applicable_licenses = ["@rules_java//:license"]) + +# Make a sample jar for the http_jar test. +java_library( + name = "my_jar", + srcs = ["MyLib.java"], +) + +# Used by //test/java/common/rules/java_binary_tests.bzl%_test_java_binary_java_package +util.helper_target( + java_binary, + name = "non_java", + srcs = ["Foo.java"], + visibility = [ + "//test/java/common/rules:__pkg__", + ], +) diff --git a/test/testdata/BUILD.bazel b/test/testdata/BUILD.bazel deleted file mode 100644 index 7a0c7589..00000000 --- a/test/testdata/BUILD.bazel +++ /dev/null @@ -1,9 +0,0 @@ -load("//java:java_library.bzl", "java_library") - -package(default_applicable_licenses = ["@rules_java//:license"]) - -# Make a sample jar for the http_jar test. -java_library( - name = "my_jar", - srcs = ["MyLib.java"], -) From 235f8ac881e5d2f7cf60deb4fee81415c5af38e1 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 22 Jun 2026 01:13:45 -0700 Subject: [PATCH 184/251] Add a test for a `java_binary` rule in a subdirectory. (ignore-relnotes) PiperOrigin-RevId: 935905817 Change-Id: I38f5b063f24a78dba5f0a9257e34242188af97ea --- test/java/common/rules/java_binary_tests.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 05e7e8a6..f5411337 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -442,6 +442,20 @@ def _test_java_binary_java_package_impl(env, target): "main_class was not provided and cannot be inferred", )) +# Regression test for CL 7314966. +def _test_java_binary_rule_in_sub_directory(name): + util.helper_target( + java_binary, + name = "subdir/MyBinary", + srcs = ["subdir/MyBinary.java"], + ) + + analysis_test( + name = name, + impl = lambda *args, **kwargs: None, # should not be an error + target = "subdir/MyBinary", + ) + def java_binary_tests(name): test_suite( name = name, @@ -457,5 +471,6 @@ def java_binary_tests(name): _test_one_version_check_disabled, _test_java_binary_no_launcher_dep_if_not_executable, _test_java_binary_java_package, + _test_java_binary_rule_in_sub_directory, ], ) From 5bc91d55695e229bf03b48763471f4841b0240fe Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 23 Jun 2026 05:19:41 -0700 Subject: [PATCH 185/251] Add a test for a `java_binary` resources (ignore-relnotes) PiperOrigin-RevId: 936596044 Change-Id: I7425c61c244cb309178c8219ed8835e66c1e0e0d --- .../common_launcher_java_binary_tests.bzl | 54 +++++++++++++++++++ test/java/testutil/artifact_closure.bzl | 22 ++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 572f27a0..36b6c477 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -3,6 +3,9 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") +load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") def _test_java_binary_non_executable_rule_outputs(name): util.helper_target( @@ -23,10 +26,61 @@ def _test_java_binary_non_executable_rule_outputs_impl(env, target): "{package}/{name}.jar", ]) +def _test_java_binary_resources_only(name): + util.helper_target( + java_binary, + name = name + "/bin", + main_class = "doesnotmatter", + resources = [ + "someFile.xml", + "someOtherFile.xml", + ], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Xml.java"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + ) + + analysis_test( + name = name, + attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + extra_target_under_test_aspects = [artifact_closure.aspect], + impl = _test_java_binary_resources_only_impl, + target = name + "/bin", + ) + +def _test_java_binary_resources_only_impl(env, target): + deploy_jar = env.expect.that_target(target).action_named("JavaDeployJar").actual.outputs.to_list()[0] + env.expect.that_file(deploy_jar).basename().equals("bin_deploy.jar") + + # check that we do have a jar file build for bin, although + # it does not contain any source files + artifact_closure.of_target(env, target, extensions = ["jar"], initial = deploy_jar).contains_exactly([ + "{package}/JavaBuilder_deploy.jar", + "{package}/lib{test_name}/lib.jar", + "{package}/{test_name}/bin-class.jar", + "{package}/{test_name}/bin.jar", + "{package}/{test_name}/bin_deploy.jar", + ]) + artifact_closure.of_target(env, target, extensions = ["xml"], initial = deploy_jar).contains_exactly([ + "{package}/someFile.xml", + "{package}/someOtherFile.xml", + ]) + def java_binary_launcher_tests(name): test_suite( name = name, tests = [ _test_java_binary_non_executable_rule_outputs, + _test_java_binary_resources_only, ], ) diff --git a/test/java/testutil/artifact_closure.bzl b/test/java/testutil/artifact_closure.bzl index b7141f0f..48353582 100644 --- a/test/java/testutil/artifact_closure.bzl +++ b/test/java/testutil/artifact_closure.bzl @@ -4,8 +4,11 @@ load("@rules_testing//lib:truth.bzl", "subjects") # TODO: consider upstreaming this to @rules_testing -def _compute(target): - to_process = target[DefaultInfo].files.to_list() +def _compute(target, initial = None): + if not initial: + to_process = target[DefaultInfo].files.to_list() + else: + to_process = [initial] if _ArtifactActionMapInfo not in target: fail("Did you forget to add the aspect to analysis_test(extra_target_under_test_aspects = )?") map = target[_ArtifactActionMapInfo].map @@ -51,13 +54,19 @@ def _aspect_impl(target, ctx): _aspect = aspect(_aspect_impl, attr_aspects = ["*"]) -def _of_target(env, target, as_paths = True, extensions = None): +def _of_target( + env, + target, + initial = None, + as_paths = True, + extensions = None, + package_local_only = True): meta = env.expect.meta.derive(format_str_kwargs = { "name": target.label.name, "package": target.label.package, }) result = subjects.collection( - _compute(target), + _compute(target, initial = initial), meta = meta, container_name = "artifact clousre of {}".format(target.label), format = True, @@ -67,6 +76,11 @@ def _of_target(env, target, as_paths = True, extensions = None): filter = lambda f: f.extension in extensions, desc = "with extensions: {exts}".format(exts = extensions), ) + if package_local_only: + result = result.transform( + filter = lambda f: f.short_path.startswith(target.label.package), + desc = "in package: {package}".format(package = target.label.package), + ) if as_paths: result = result.transform( desc = "short_path", From 5aebf506706a4ca8c5f452570048df41bd4931c1 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 25 Jun 2026 10:48:41 -0700 Subject: [PATCH 186/251] Delete an incorrect test PiperOrigin-RevId: 938074221 Change-Id: I941d0bbecc86b7859055cdf45e4a24fef2febbf4 --- test/java/common/rules/java_test_tests.bzl | 39 ---------------------- 1 file changed, 39 deletions(-) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 995872f1..1468fcc8 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -10,7 +10,6 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") -load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/testutil:helper.bzl", "always_passes") @@ -210,43 +209,6 @@ def _test_stamp_values_impl(env, targets): env.expect.that_target(targets.defaultstamp).attr("stamp", factory = subjects.int).equals(0) env.expect.that_target(targets.autostamp).attr("stamp", factory = subjects.int).equals(-1) -def _test_add_test_support_to_compile_time_deps_flag(name): - if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: - always_passes(name) - return - util.helper_target( - rule = java_test, - name = name + "/test", - srcs = [name + "/Test.java"], - ) - - analysis_test( - name = name, - targets = { - "add_support": name + "/test", - "no_add_support": name + "/test", - }, - attrs = { - "test_runner": attr.label(default = semantics.JAVA_TEST_RUNNER_LABEL), - "add_support": { - "@config_settings": { - "//command_line_option:experimental_add_test_support_to_compile_time_deps": True, - }, - }, - "no_add_support": { - "@config_settings": { - "//command_line_option:experimental_add_test_support_to_compile_time_deps": False, - }, - }, - }, - impl = _test_add_test_support_to_compile_time_deps_flag_impl, - ) - -def _test_add_test_support_to_compile_time_deps_flag_impl(env, targets): - compile_jars = env.ctx.attr.test_runner[JavaInfo].compile_jars - env.expect.that_target(targets.add_support).action_named("Javac").inputs().contains_at_least(compile_jars.to_list()) - env.expect.that_target(targets.no_add_support).action_named("Javac").inputs().contains_none_of(compile_jars.to_list()) - def _test_mac_requires_darwin_for_execution(name): util.helper_target( rule = native.platform, @@ -443,7 +405,6 @@ def java_test_tests(name): _test_java_test_propagates_direct_native_libraries, _test_coverage_uses_coverage_runner_for_main, _test_stamp_values, - _test_add_test_support_to_compile_time_deps_flag, _test_mac_requires_darwin_for_execution, _test_java_test_sets_securiry_manager_property_jdk17, _test_one_version_check_java_test, From 6c504056e873ffb92f03bbace9fb49e02ac23578 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 29 Jun 2026 01:48:42 -0700 Subject: [PATCH 187/251] Add a test for `java_binary` deploy jar coverage setup (ignore-relnotes) PiperOrigin-RevId: 939692972 Change-Id: I6d44be5ebcb4248eeda56ca06ff4eb46711e0881 --- .../common_launcher_java_binary_tests.bzl | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 36b6c477..595b348d 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -76,11 +76,33 @@ def _test_java_binary_resources_only_impl(env, target): "{package}/someOtherFile.xml", ]) +def _test_java_binary_deploy_jar_coverage_setup(name): + util.helper_target( + java_binary, + name = name + "/app", + main_class = "com.google.app", + ) + + analysis_test( + name = name, + attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 + config_settings = { + "//command_line_option:collect_code_coverage": True, + }, + impl = _test_java_binary_deploy_jar_coverage_setup_impl, + target = name + "/app", + ) + +def _test_java_binary_deploy_jar_coverage_setup_impl(env, target): + assert_that_action = env.expect.that_target(target).action_generating("{package}/{name}_deploy.jar") + assert_that_action.argv().contains("Coverage-Main-Class: com.google.app") + def java_binary_launcher_tests(name): test_suite( name = name, tests = [ _test_java_binary_non_executable_rule_outputs, _test_java_binary_resources_only, + _test_java_binary_deploy_jar_coverage_setup, ], ) From 97e35ce587b7ea9bc26a21e533d3b1f9f2acbb08 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 30 Jun 2026 03:29:04 -0700 Subject: [PATCH 188/251] Add a test for `java_binary` with a transitive dep on `java_library` (ignore-relnotes) PiperOrigin-RevId: 940357802 Change-Id: I7d16dc44fb992908d1f04ec693426d120fdd2948 --- .../common_launcher_java_binary_tests.bzl | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 595b348d..122d26ce 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -97,6 +97,39 @@ def _test_java_binary_deploy_jar_coverage_setup_impl(env, target): assert_that_action = env.expect.that_target(target).action_generating("{package}/{name}_deploy.jar") assert_that_action.argv().contains("Coverage-Main-Class: com.google.app") +def _test_java_binary_transitive_dependency_from_java_library(name): + util.helper_target( + java_binary, + name = name + "/Binary", + srcs = ["Binary.java"], + deps = [name + "/somedep"], + ) + util.helper_target( + java_library, + name = name + "/somedep", + srcs = ["Dependency.java"], + deps = [name + "/otherdep"], + ) + util.helper_target( + java_library, + name = name + "/otherdep", + srcs = ["OtherDependency.java"], + ) + + analysis_test( + name = name, + extra_target_under_test_aspects = [artifact_closure.aspect], + impl = _test_java_binary_transitive_dependency_from_java_library_impl, + target = name + "/Binary", + ) + +def _test_java_binary_transitive_dependency_from_java_library_impl(env, target): + artifact_closure.of_target(env, target, extensions = ["java"]).contains_exactly([ + "{package}/Binary.java", + "{package}/Dependency.java", + "{package}/OtherDependency.java", + ]) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -104,5 +137,6 @@ def java_binary_launcher_tests(name): _test_java_binary_non_executable_rule_outputs, _test_java_binary_resources_only, _test_java_binary_deploy_jar_coverage_setup, + _test_java_binary_transitive_dependency_from_java_library, ], ) From f4e1786bd720ae55a10918b953df6fa2fa35423e Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 1 Jul 2026 01:40:33 -0700 Subject: [PATCH 189/251] Add a test for `java_binary` with an explicit `main_class` (ignore-relnotes) PiperOrigin-RevId: 940934897 Change-Id: I49e9fb0e03bea872dd27a99f5f764da390aaba18 --- .../common_launcher_java_binary_tests.bzl | 20 ++++++++++++++ .../testutil/binary_executable_subject.bzl | 26 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/java/testutil/binary_executable_subject.bzl diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 122d26ce..c0fd9468 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -5,6 +5,7 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") +load("//test/java/testutil:binary_executable_subject.bzl", "expect_that_executable") load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") def _test_java_binary_non_executable_rule_outputs(name): @@ -130,6 +131,24 @@ def _test_java_binary_transitive_dependency_from_java_library_impl(env, target): "{package}/OtherDependency.java", ]) +def _test_java_binary_explicit_main_class(name): + util.helper_target( + java_binary, + name = name + "/bin", + main_class = "foo.bar.baz", + ) + + analysis_test( + name = name, + impl = _test_java_binary_explicit_main_class_impl, + target = name + "/bin", + ) + +def _test_java_binary_explicit_main_class_impl(env, target): + expect_that_executable.of_target(env, target).java_start_class().equals( + "foo.bar.baz", + ) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -138,5 +157,6 @@ def java_binary_launcher_tests(name): _test_java_binary_resources_only, _test_java_binary_deploy_jar_coverage_setup, _test_java_binary_transitive_dependency_from_java_library, + _test_java_binary_explicit_main_class, ], ) diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl new file mode 100644 index 00000000..189e1d2b --- /dev/null +++ b/test/java/testutil/binary_executable_subject.bzl @@ -0,0 +1,26 @@ +"""Custom rules_testing subject for java_binary/java_test executable output""" + +load("@rules_testing//lib:truth.bzl", "subjects") + +def _of_target(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + action_subject = env.expect.that_target(target).action_generating(executable) + public = struct( + java_start_class = lambda: _java_start_class_subject(action_subject), + ) + return public + +def _java_start_class_subject(action): + if action.actual.substitutions: + return action.substitutions().get("%java_start_class%", factory = subjects.str) + else: + # Windows + return action.argv().transform( + filter = lambda e: e.startswith("java_start_class="), + map_each = lambda e: e.split("=", 1)[1], + desc = "java_start_class", + ).offset(0, factory = subjects.str) + +expect_that_executable = struct( + of_target = _of_target, +) From 166f9c92d408d704848b657ab4574e29707ffc62 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 3 Jul 2026 00:39:00 -0700 Subject: [PATCH 190/251] Add a test for `java_binary` with an implicit `main_class` (ignore-relnotes) PiperOrigin-RevId: 941992032 Change-Id: If53b673e7ad1b8c33370643172275fa8bbd0ed5a --- .../common_launcher_java_binary_tests.bzl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index c0fd9468..b3ffd0c7 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -149,6 +149,24 @@ def _test_java_binary_explicit_main_class_impl(env, target): "foo.bar.baz", ) +def _test_java_binary_implicit_main_class(name): + util.helper_target( + java_binary, + name = name + "/Binary", + srcs = ["Binary.java"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_implicit_main_class_impl, + target = name + "/Binary", + ) + +def _test_java_binary_implicit_main_class_impl(env, target): + expect_that_executable.of_target(env, target).java_start_class().equals( + "common.rules.{test_name}.Binary".format(test_name = env.ctx.label.name), + ) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -158,5 +176,6 @@ def java_binary_launcher_tests(name): _test_java_binary_deploy_jar_coverage_setup, _test_java_binary_transitive_dependency_from_java_library, _test_java_binary_explicit_main_class, + _test_java_binary_implicit_main_class, ], ) From 9b487a5c6b20c9f48dcd0d650dff90e23220d6c7 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 8 Jul 2026 09:20:23 -0700 Subject: [PATCH 191/251] Add a test for `java_test` with an implicit `main_class` (ignore-relnotes) PiperOrigin-RevId: 944538181 Change-Id: I93c89986d07f8287ffb75f12e8bb8508a1dd9408 --- .../common_launcher_java_binary_tests.bzl | 19 +++++++++++++++++++ .../testutil/binary_executable_subject.bzl | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index b3ffd0c7..f09d2dc9 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -4,6 +4,7 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") +load("//java:java_test.bzl", "java_test") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") load("//test/java/testutil:binary_executable_subject.bzl", "expect_that_executable") load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") @@ -167,6 +168,23 @@ def _test_java_binary_implicit_main_class_impl(env, target): "common.rules.{test_name}.Binary".format(test_name = env.ctx.label.name), ) +def _test_java_test_main_class(name): + util.helper_target( + java_test, + name = name + "/Test", + ) + + analysis_test( + name = name, + impl = _test_java_test_main_class_impl, + target = name + "/Test", + ) + +def _test_java_test_main_class_impl(env, target): + expect_that_executable.of_target(env, target).test_suite().equals( + "common.rules.{test_name}.Test".format(test_name = env.ctx.label.name), + ) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -177,5 +195,6 @@ def java_binary_launcher_tests(name): _test_java_binary_transitive_dependency_from_java_library, _test_java_binary_explicit_main_class, _test_java_binary_implicit_main_class, + _test_java_test_main_class, ], ) diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl index 189e1d2b..818d66e9 100644 --- a/test/java/testutil/binary_executable_subject.bzl +++ b/test/java/testutil/binary_executable_subject.bzl @@ -1,12 +1,14 @@ """Custom rules_testing subject for java_binary/java_test executable output""" load("@rules_testing//lib:truth.bzl", "subjects") +load("//java/common:java_semantics.bzl", "semantics") def _of_target(env, target): executable = target[DefaultInfo].files_to_run.executable.short_path action_subject = env.expect.that_target(target).action_generating(executable) public = struct( java_start_class = lambda: _java_start_class_subject(action_subject), + test_suite = lambda: _test_suite_subject(action_subject), ) return public @@ -21,6 +23,22 @@ def _java_start_class_subject(action): desc = "java_start_class", ).offset(0, factory = subjects.str) +def _test_suite_subject(action): + if action.actual.substitutions: + jvm_flags = action.substitutions().get("%jvm_flags%", factory = subjects.str).split(" ") + else: + # Windows + jvm_flags = action.argv().transform( + filter = lambda e: e.startswith("jvm_flags="), + map_each = lambda e: e.split("=", 1)[1], + desc = "jvm_flags", + ).offset(0, factory = subjects.str).split("\t") + return jvm_flags.transform( + filter = lambda e: e.startswith("-D" + semantics.TEST_SUITE_PROPERTY_NAME + "="), + map_each = lambda e: e.split("=", 1)[1], + desc = semantics.TEST_SUITE_PROPERTY_NAME, + ).offset(0, factory = subjects.str) + expect_that_executable = struct( of_target = _of_target, ) From 5f71e54c5fa7089b3ff92f30ec58b675a7366754 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 9 Jul 2026 01:37:26 -0700 Subject: [PATCH 192/251] Add a test for `java_test` with a `main_class` containing a `.` (ignore-relnotes) PiperOrigin-RevId: 944970578 Change-Id: Ia1c76d0bcd9d77ace8654117d2d5aac25410d285 --- .../common_launcher_java_binary_tests.bzl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index f09d2dc9..6a71904c 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -185,6 +185,23 @@ def _test_java_test_main_class_impl(env, target): "common.rules.{test_name}.Test".format(test_name = env.ctx.label.name), ) +def _test_java_test_main_class_with_dot(name): + util.helper_target( + java_test, + name = name + "/withdot.Test", + ) + + analysis_test( + name = name, + impl = _test_java_test_main_class_with_dot_impl, + target = name + "/withdot.Test", + ) + +def _test_java_test_main_class_with_dot_impl(env, target): + expect_that_executable.of_target(env, target).test_suite().equals( + "common.rules.{test_name}.withdot.Test".format(test_name = env.ctx.label.name), + ) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -196,5 +213,6 @@ def java_binary_launcher_tests(name): _test_java_binary_explicit_main_class, _test_java_binary_implicit_main_class, _test_java_test_main_class, + _test_java_test_main_class_with_dot, ], ) From e06bb23b23e08e5557fe54da97e033eab770465b Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Mon, 13 Jul 2026 04:46:35 -0700 Subject: [PATCH 193/251] Return repo_metadata from repository_rules (#367) This is used by bazel to determine that these rules are remotely cacheable with the remote repo contents cache. Closes #367 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/367 from keith:ks/return-repo_metadata-from-repository_rules f9d9c79fce4d90ca021368b268dac7fd4a879b8c PiperOrigin-RevId: 946959010 Change-Id: Ic5537bf0e2b825d67061be55f61250e770e279b7 --- java/rules_java_deps.bzl | 4 ++++ toolchains/local_java_repository.bzl | 10 ++++++++-- toolchains/remote_java_repository.bzl | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/java/rules_java_deps.bzl b/java/rules_java_deps.bzl index b2086dc1..c9742f94 100644 --- a/java/rules_java_deps.bzl +++ b/java/rules_java_deps.bzl @@ -103,6 +103,10 @@ http_jar = _http_jar """, ) + if hasattr(rctx, "repo_metadata"): + return rctx.repo_metadata(reproducible = True) + return None + _compatibility_proxy_repo_rule = repository_rule( _compatibility_proxy_repo_impl, # force reruns on server restarts to use correct native.bazel_version diff --git a/toolchains/local_java_repository.bzl b/toolchains/local_java_repository.bzl index 769c2d19..88115bb7 100644 --- a/toolchains/local_java_repository.bzl +++ b/toolchains/local_java_repository.bzl @@ -176,6 +176,10 @@ def _local_java_repository_impl(repository_ctx): repository_ctx: repository context """ + repository_metadata = None + if hasattr(repository_ctx, "repo_metadata"): + repository_metadata = repository_ctx.repo_metadata(reproducible = True) + java_home = _determine_java_home(repository_ctx) local_java_runtime_name = repository_ctx.attr.runtime_name @@ -198,7 +202,7 @@ def _local_java_repository_impl(repository_ctx): "either correct your JAVA_HOME, PATH or specify Java from " + "remote repository (e.g. --java_runtime_version=remotejdk_11)", ) - return + return repository_metadata # Detect version version = repository_ctx.attr.version if repository_ctx.attr.version != "" else _detect_java_version(repository_ctx, java_bin) @@ -211,7 +215,7 @@ def _local_java_repository_impl(repository_ctx): message = "Cannot detect Java version of {java_binary} in {java_home}; " + "make sure it points to a valid Java executable", ) - return + return repository_metadata # Prepare BUILD file using "local_java_runtime" macro if repository_ctx.attr.build_file_content and repository_ctx.attr.build_file: @@ -247,6 +251,8 @@ local_java_runtime( for file in repository_ctx.path(java_home).readdir(): repository_ctx.symlink(file, file.basename) + return repository_metadata + # Build file template, when JDK could not be detected _AUTO_CONFIG_ERROR_BUILD_TPL = '''load("@rules_java//toolchains:fail_rule.bzl", "fail_rule") fail_rule( diff --git a/toolchains/remote_java_repository.bzl b/toolchains/remote_java_repository.bzl index 65bbe482..500beb7b 100644 --- a/toolchains/remote_java_repository.bzl +++ b/toolchains/remote_java_repository.bzl @@ -23,6 +23,9 @@ load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE") def _toolchain_config_impl(ctx): ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name)) ctx.file("BUILD.bazel", ctx.attr.build_file) + if hasattr(ctx, "repo_metadata"): + return ctx.repo_metadata(reproducible = True) + return None _toolchain_config = repository_rule( local = True, From 899c55129a9e087f01c4485158958573c6e329cd Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 14 Jul 2026 07:50:01 -0700 Subject: [PATCH 194/251] Upgrade default JDK to 25. PiperOrigin-RevId: 947681426 Change-Id: I7ac6088148628c16ed2cb05ff0cc9b4d867376c5 --- toolchains/default_java_toolchain.bzl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index f4f83f66..e4097ae0 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -99,9 +99,7 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict( reduced_classpath_incompatible_processors = [ "dagger.hilt.processor.internal.root.RootProcessor", # see b/21307381 ], - # TODO: Update to JDK 25 after some time has passed - it no longer supports - # targeting JDK 7. - java_runtime = Label("//toolchains:remotejdk_21"), + java_runtime = Label("//toolchains:remotejdk_25"), oneversion = Label("//toolchains:one_version"), ) From ed0a552e93dbb7473c79949a86415d52dfb3245a Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 15 Jul 2026 02:19:58 -0700 Subject: [PATCH 195/251] Remove `java_runtime` override No longer necessary after https://github.com/bazelbuild/rules_java/commit/899c55129a9e087f01c4485158958573c6e329cd which made it the default. (ignore-relnotes) PiperOrigin-RevId: 948202174 Change-Id: I87341f71f3f109f94d57533a29886eaed2a6407b --- toolchains/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchains/BUILD b/toolchains/BUILD index 30b78e59..25795555 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -366,7 +366,7 @@ RELEASES = (8, 9, 10, 11, 17, 21, 25) [ default_java_toolchain( name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release, - configuration = DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_25"}, + configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, source_version = "%s" % release, target_version = "%s" % release, ) From 9ed4512c3d10bca7c380f21dc73a31dec04ff09c Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 23 Jul 2026 03:10:20 -0700 Subject: [PATCH 196/251] Add a test that `java_test` has assertions enabled. (ignore-relnotes) PiperOrigin-RevId: 952644847 Change-Id: I4cec6bd7bc221d1042867e8e399f9513916b31ae --- .../rules/common_launcher_java_binary_tests.bzl | 16 ++++++++++++++++ .../java/testutil/binary_executable_subject.bzl | 17 ++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 6a71904c..56b49d36 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -202,6 +202,21 @@ def _test_java_test_main_class_with_dot_impl(env, target): "common.rules.{test_name}.withdot.Test".format(test_name = env.ctx.label.name), ) +def _test_java_test_has_assertions_enabled(name): + util.helper_target( + java_test, + name = name + "/testea", + ) + + analysis_test( + name = name, + impl = _test_java_test_has_assertions_enabled_impl, + target = name + "/testea", + ) + +def _test_java_test_has_assertions_enabled_impl(env, target): + expect_that_executable.of_target(env, target).jvm_flags().contains("-ea") + def java_binary_launcher_tests(name): test_suite( name = name, @@ -214,5 +229,6 @@ def java_binary_launcher_tests(name): _test_java_binary_implicit_main_class, _test_java_test_main_class, _test_java_test_main_class_with_dot, + _test_java_test_has_assertions_enabled, ], ) diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl index 818d66e9..8e615a03 100644 --- a/test/java/testutil/binary_executable_subject.bzl +++ b/test/java/testutil/binary_executable_subject.bzl @@ -9,6 +9,7 @@ def _of_target(env, target): public = struct( java_start_class = lambda: _java_start_class_subject(action_subject), test_suite = lambda: _test_suite_subject(action_subject), + jvm_flags = lambda: _jvm_flags_subject(action_subject), ) return public @@ -24,20 +25,22 @@ def _java_start_class_subject(action): ).offset(0, factory = subjects.str) def _test_suite_subject(action): + return _jvm_flags_subject(action).transform( + filter = lambda e: e.startswith("-D" + semantics.TEST_SUITE_PROPERTY_NAME + "="), + map_each = lambda e: e.split("=", 1)[1], + desc = semantics.TEST_SUITE_PROPERTY_NAME, + ).offset(0, factory = subjects.str) + +def _jvm_flags_subject(action): if action.actual.substitutions: - jvm_flags = action.substitutions().get("%jvm_flags%", factory = subjects.str).split(" ") + return action.substitutions().get("%jvm_flags%", factory = subjects.str).split(" ") else: # Windows - jvm_flags = action.argv().transform( + return action.argv().transform( filter = lambda e: e.startswith("jvm_flags="), map_each = lambda e: e.split("=", 1)[1], desc = "jvm_flags", ).offset(0, factory = subjects.str).split("\t") - return jvm_flags.transform( - filter = lambda e: e.startswith("-D" + semantics.TEST_SUITE_PROPERTY_NAME + "="), - map_each = lambda e: e.split("=", 1)[1], - desc = semantics.TEST_SUITE_PROPERTY_NAME, - ).offset(0, factory = subjects.str) expect_that_executable = struct( of_target = _of_target, From 2f4643b465ab353d84c63e2b246c286c24351d67 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 27 Jul 2026 07:04:01 -0700 Subject: [PATCH 197/251] Add a test for `java_binary` native library paths with transitive deps. (ignore-relnotes) PiperOrigin-RevId: 954607707 Change-Id: I163f3820d33bc0f2c0b34af2b66dc9ffc365b96b --- .../common_launcher_java_binary_tests.bzl | 56 +++++++++++++++++++ .../testutil/binary_executable_subject.bzl | 18 ++++++ 2 files changed, 74 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 56b49d36..b2cc2062 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -1,10 +1,13 @@ """Parameterized tests for java_binary with --java_launcher""" +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") +load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") load("//test/java/testutil:binary_executable_subject.bzl", "expect_that_executable") load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") @@ -217,6 +220,58 @@ def _test_java_test_has_assertions_enabled(name): def _test_java_test_has_assertions_enabled_impl(env, target): expect_that_executable.of_target(env, target).jvm_flags().contains("-ea") +# Tests that the native library path computed from a ".so" cc_binary dependency +# includes the transitive closure of that dependency. +def _test_java_binary_native_library_path_includes_transitive_deps(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["DoesNotMatter.java"], + deps = [name + "/jni.so"], + ) + util.helper_target( + java_binary, + name = name + "/runtime_app", + srcs = ["AlsoDoesNotMatter.java"], + runtime_deps = [name + "/jni.so"], + ) + util.helper_target( + cc_binary, + name = name + "/jni.so", + srcs = ["lib1.so"], + deps = [name + "/helper_lib"], + ) + util.helper_target( + cc_library, + name = name + "/helper_lib", + srcs = ["lib2.so"], + ) + + analysis_test( + name = name, + attrs = { + "_windows_constraints": attr.label_list(default = ["@platforms//os:windows"]), + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + }, + impl = _test_java_binary_native_library_path_includes_transitive_deps_impl, + target = [ + name + "/app", + name + "/runtime_app", + ], + ) + +def _test_java_binary_native_library_path_includes_transitive_deps_impl(env, targets): + for target in targets: + if helper.is_target_platform_windows(env.ctx): + expect_that_executable.of_target(env, target).native_library_paths().contains_exactly([ + "${{JAVA_RUNFILES}}/{workspace}/{package}", + ]) + else: + expect_that_executable.of_target(env, target).native_library_paths().contains_exactly([ + "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/helper_lib___{package}", + "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/jni.so___{package}", + ]) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -230,5 +285,6 @@ def java_binary_launcher_tests(name): _test_java_test_main_class, _test_java_test_main_class_with_dot, _test_java_test_has_assertions_enabled, + _test_java_binary_native_library_path_includes_transitive_deps, ], ) diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl index 8e615a03..df5c4774 100644 --- a/test/java/testutil/binary_executable_subject.bzl +++ b/test/java/testutil/binary_executable_subject.bzl @@ -1,5 +1,6 @@ """Custom rules_testing subject for java_binary/java_test executable output""" +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_testing//lib:truth.bzl", "subjects") load("//java/common:java_semantics.bzl", "semantics") @@ -10,6 +11,7 @@ def _of_target(env, target): java_start_class = lambda: _java_start_class_subject(action_subject), test_suite = lambda: _test_suite_subject(action_subject), jvm_flags = lambda: _jvm_flags_subject(action_subject), + native_library_paths = lambda: _native_library_paths_subject(action_subject), ) return public @@ -42,6 +44,22 @@ def _jvm_flags_subject(action): desc = "jvm_flags", ).offset(0, factory = subjects.str).split("\t") +def _native_library_paths_subject(action): + return _jvm_flags_subject(action).transform( + filter = lambda e: e.startswith("-Djava.library.path="), + map_each = lambda e: e.split("=", 1)[1], + desc = "native library paths", + ).offset( + 0, + factory = lambda actual, meta: subjects.str(actual, meta.derive( + format_str_kwargs = {"cpu": meta.ctx.attr._cc_toolchain[cc_common.CcToolchainInfo].cpu}, + )), + ).split(":").transform( + map_each = lambda e: e.replace("_U", "_").replace("_S", "/").replace("_C", ":"), + desc = "pretty", + format = True, + ) + expect_that_executable = struct( of_target = _of_target, ) From df48f45ec2e770bb343404d21b8ddf95b7e11298 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 29 Jul 2026 02:48:54 -0700 Subject: [PATCH 198/251] Internal change (ignore-relnotes) PiperOrigin-RevId: 955764005 Change-Id: I5fa9b8bcc64ab1df8caf77fa01153b01ef018a69 --- java/testutil.bzl | 4 ++++ test/java/testutil/cc_info_subject.bzl | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/java/testutil.bzl b/java/testutil.bzl index 4063ea6f..cc7c2ec5 100644 --- a/java/testutil.bzl +++ b/java/testutil.bzl @@ -12,7 +12,11 @@ def _cc_info_transitive_native_libraries(cc_info): def _cc_library_to_link_static_library(library_to_link): return library_to_link.static_library or library_to_link.pic_static_library +def _cc_library_to_link_dynamic_library(library_to_link): + return library_to_link.interface_library or library_to_link.dynamic_library + testutil = struct( cc_info_transitive_native_libraries = _cc_info_transitive_native_libraries, cc_library_to_link_static_library = _cc_library_to_link_static_library, + cc_library_to_link_dynamic_library = _cc_library_to_link_dynamic_library, ) diff --git a/test/java/testutil/cc_info_subject.bzl b/test/java/testutil/cc_info_subject.bzl index b50ff2e6..3fd8f860 100644 --- a/test/java/testutil/cc_info_subject.bzl +++ b/test/java/testutil/cc_info_subject.bzl @@ -72,6 +72,7 @@ def _new_cc_info_libraries_to_link_subject(libraries_to_link, meta): ) public = struct( static_libraries = lambda: _new_library_to_link_static_libraries_subject(self.actual, self.meta), + dynamic_libraries = lambda: _new_library_to_link_dynamic_libraries_subject(self.actual, self.meta), singleton = lambda: _new_library_to_link_subject(_get_singleton(self.actual), self.meta.derive("[0]")), ) return public @@ -93,6 +94,12 @@ def _new_library_to_link_static_libraries_subject(libraries_to_link, meta): ) return public +def _new_library_to_link_dynamic_libraries_subject(libraries_to_link, meta): + return subjects.depset_file( + [testutil.cc_library_to_link_dynamic_library(lib) for lib in libraries_to_link], + meta = meta.derive("dynamic_library()"), + ) + def _get_singleton(seq): if len(seq) != 1: fail("expected singleton, got:", seq) From 54cc8ede6e11b5716b9fcb31d4ff6ec932304b14 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 31 Jul 2026 02:26:03 -0700 Subject: [PATCH 199/251] Add a test for `java_binary` with inner main class. (ignore-relnotes) PiperOrigin-RevId: 957013088 Change-Id: I35dc02128002d12fc41213703159d108233daa0b --- .../common_launcher_java_binary_tests.bzl | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index b2cc2062..ac4baac8 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -272,6 +272,29 @@ def _test_java_binary_native_library_path_includes_transitive_deps_impl(env, tar "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/jni.so___{package}", ]) +# Regression test for bug 2774317: Problems with inner classes as main class. +def _test_java_binary_inner_class(name): + util.helper_target( + java_binary, + name = name + "/inner", + srcs = ["Main.java"], + main_class = "Main$Inner", + ) + + analysis_test( + name = name, + attrs = {"_windows_constraints": attr.label_list(default = ["@platforms//os:windows"])}, + impl = _test_java_binary_inner_class_impl, + target = name + "/inner", + ) + +def _test_java_binary_inner_class_impl(env, target): + if helper.is_target_platform_windows(env.ctx): + expected = "Main$Inner" # unquoted on windows + else: + expected = "'Main$Inner'" # shell-quoted + expect_that_executable.of_target(env, target).java_start_class().equals(expected) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -286,5 +309,6 @@ def java_binary_launcher_tests(name): _test_java_test_main_class_with_dot, _test_java_test_has_assertions_enabled, _test_java_binary_native_library_path_includes_transitive_deps, + _test_java_binary_inner_class, ], ) From 8a67bfac1e67a016c3c1d9a0251ac01226d3b6d9 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 3 Aug 2026 01:30:14 -0700 Subject: [PATCH 200/251] Add a test for `java_test` with inner test class. (ignore-relnotes) PiperOrigin-RevId: 958229152 Change-Id: I0398c77612560dfbddb907b7fb72c7f9fe2a08e7 --- .../common_launcher_java_binary_tests.bzl | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index ac4baac8..dc3d18d5 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -295,6 +295,27 @@ def _test_java_binary_inner_class_impl(env, target): expected = "'Main$Inner'" # shell-quoted expect_that_executable.of_target(env, target).java_start_class().equals(expected) +def _test_java_test_inner_class(name): + util.helper_target( + java_test, + name = name + "/inner", + test_class = "Outer$Inner", + ) + + analysis_test( + name = name, + attrs = {"_windows_constraints": attr.label_list(default = ["@platforms//os:windows"])}, + impl = _test_java_test_inner_class_impl, + target = name + "/inner", + ) + +def _test_java_test_inner_class_impl(env, target): + if helper.is_target_platform_windows(env.ctx): + expected = "Outer$Inner" # unquoted on windows + else: + expected = "'Outer$Inner'" # shell-quoted + expect_that_executable.of_target(env, target).test_suite().equals(expected) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -310,5 +331,6 @@ def java_binary_launcher_tests(name): _test_java_test_has_assertions_enabled, _test_java_binary_native_library_path_includes_transitive_deps, _test_java_binary_inner_class, + _test_java_test_inner_class, ], ) From c5a676da49caee5b60ff24e88e63b143303eac89 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 5 Aug 2026 01:36:58 -0700 Subject: [PATCH 201/251] Add a test for `java_binary` with duplicate classpath resources. (ignore-relnotes) PiperOrigin-RevId: 959503952 Change-Id: I11d3ac3781d78c11ba8ad68e0b3da84483d36681 --- test/java/common/rules/java_binary_tests.bzl | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index f5411337..9bb7fa85 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -456,6 +456,39 @@ def _test_java_binary_rule_in_sub_directory(name): target = "subdir/MyBinary", ) +def _test_java_binary_duplicate_classpath_resources(name): + util.helper_target( + native.filegroup, + name = name + "/a", + srcs = ["a/same.txt"], + ) + util.helper_target( + native.filegroup, + name = name + "/b", + srcs = ["b/same.txt"], + ) + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + classpath_resources = [ + name + "/a", + name + "/b", + ], + ) + + analysis_test( + name = name, + impl = _test_java_binary_duplicate_classpath_resources_impl, + target = name + "/app", + expect_failure = True, + ) + +def _test_java_binary_duplicate_classpath_resources_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("entries must have different file names (duplicate: same.txt)"), + ) + def java_binary_tests(name): test_suite( name = name, @@ -472,5 +505,6 @@ def java_binary_tests(name): _test_java_binary_no_launcher_dep_if_not_executable, _test_java_binary_java_package, _test_java_binary_rule_in_sub_directory, + _test_java_binary_duplicate_classpath_resources, ], ) From ed021f9a2e6f405317012ac0ecc51c12f01d1ff7 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 6 Aug 2026 05:50:40 -0700 Subject: [PATCH 202/251] Fix `check_remote_jdk_configs.sh` for archives with nested layouts Instead of looking at just the top level directory, we find the first '/bin' directory (or symlink). Context from https://github.com/bazelbuild/rules_java/pull/370 `Note that Azul changed the layout of the macOS tar.gz archives after 21.0.9: they now contain a macOS application bundle with the JDK under Contents/Home instead of a flat JDK image (the Zulu 25 macOS archives are still flat). The strip_prefix of the two macOS entries therefore descends into Contents/Home.` (ignore-relnotes) PiperOrigin-RevId: 960249078 Change-Id: I7b4e93dfc395985a672795204cad10fba20fcf93 --- test/check_remote_jdk_configs.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/check_remote_jdk_configs.sh b/test/check_remote_jdk_configs.sh index b1c509fe..09930bee 100755 --- a/test/check_remote_jdk_configs.sh +++ b/test/check_remote_jdk_configs.sh @@ -27,15 +27,16 @@ for config in "$@"; do exit 1 fi if [[ -z "${url##*.tar.gz}" ]]; then - root_dir=$(tar ztf ${TMP_FILE} --exclude='*/*') + bin_dir=$(tar ztf ${TMP_FILE} | egrep '/bin(|/)$' | sort | head -n1) elif [[ -z "${url##*.zip}" ]]; then - root_dir=$(unzip -Z1 ${TMP_FILE} | head -n1) + bin_dir=$(unzip -Z1 ${TMP_FILE} | egrep '/bin(|/)/$' | sort | head -n1) else echo "ERROR: unexpected archive type for ${name}" exit 1 fi - if [ "${root_dir}" != "${strip_prefix}/" ]; then - echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" + root_dir="${bin_dir%/bin*}" + if [ "${root_dir}" != "${strip_prefix}" ]; then + echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}, got: ${root_dir}" exit 1 fi if [[ -n "${mirror_url}" ]]; then From 8211ed67ba309789a6353b21414785fac6ecb024 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 7 Aug 2026 01:03:10 -0700 Subject: [PATCH 203/251] Limit test output unless debugging (ignore-relnotes) PiperOrigin-RevId: 960764266 Change-Id: I74b9b23c3accf0cdafd5126bccef771af71d4d18 --- test/check_remote_jdk_configs.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/check_remote_jdk_configs.sh b/test/check_remote_jdk_configs.sh index 09930bee..cea093c0 100755 --- a/test/check_remote_jdk_configs.sh +++ b/test/check_remote_jdk_configs.sh @@ -13,34 +13,41 @@ # See the License for the specific language governing permissions and # limitations under the License. +function fail() { + echo "$@" + exit 1 +} + +function debug_log() { + # bazel test --test_env=DEBUG=1 ... + [[ -z "${DEBUG}" ]] || echo "$@" +} + echo "Checking hashes and strip_prefix for $# configs" _MISSING_MIRRORS=() for config in "$@"; do TMP_FILE=$(mktemp -q /tmp/remotejdk.XXXXXX) IFS=, read -r name url mirror_url hash strip_prefix <<< "${config}" - echo "fetching $name from $url to ${TMP_FILE}" + debug_log "fetching $name from $url to ${TMP_FILE}" curl --silent -o ${TMP_FILE} -L "$url" actual_hash=$(sha256sum ${TMP_FILE} | cut -d' ' -f1) if [ "${hash}" != "${actual_hash}" ]; then - echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" - exit 1 + fail "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" fi if [[ -z "${url##*.tar.gz}" ]]; then bin_dir=$(tar ztf ${TMP_FILE} | egrep '/bin(|/)$' | sort | head -n1) elif [[ -z "${url##*.zip}" ]]; then bin_dir=$(unzip -Z1 ${TMP_FILE} | egrep '/bin(|/)/$' | sort | head -n1) else - echo "ERROR: unexpected archive type for ${name}" - exit 1 + fail "ERROR: unexpected archive type for ${name}" fi root_dir="${bin_dir%/bin*}" if [ "${root_dir}" != "${strip_prefix}" ]; then - echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}, got: ${root_dir}" - exit 1 + fail "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}, got: ${root_dir}" fi if [[ -n "${mirror_url}" ]]; then - echo "checking mirror: ${mirror_url}" + debug_log "checking mirror: ${mirror_url}" curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+=("${url}"); } fi done From 8309c61d34cee16787e08ed61474f5b4af9bf0ae Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 7 Aug 2026 01:42:11 -0700 Subject: [PATCH 204/251] Delete downloaded archive after hashing in dump_remote_jdk_configs (#372) The dump_remote_jdk_configs genrule downloads each remote JDK archive to a per-iteration mktemp file to compute its sha256, but never removes it. A full run fetches every configured JDK (all versions and platforms, ~200 MB each), so it leaves roughly 7 GB of archives behind in /tmp. Remove the temp file at the end of each loop iteration, keeping peak /tmp usage to a single archive instead of the whole set. Closes #372 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/372 from davido:cleanup-dump-jdk-configs-tmpfiles 2925ac55a7c03a087cec045688f01ab9c0493934 PiperOrigin-RevId: 960780649 Change-Id: I595703b694a6c131c2fbcf7c193acc36a6bb8ebd --- java/bazel/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/java/bazel/BUILD.bazel b/java/bazel/BUILD.bazel index 225628e8..f3c47cf7 100644 --- a/java/bazel/BUILD.bazel +++ b/java/bazel/BUILD.bazel @@ -39,6 +39,7 @@ while read -r config; do echo " urls = $$urls," echo " version = \\"$$version\\"," echo ")," + rm -f "$$TMP_FILE" done <<< '{configs}' >> $@ """.format(configs = "\n".join([ "|".join([ From 1ccc4bed30ee62ee1cf9bee4cc6204139c530d2a Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 7 Aug 2026 05:53:00 -0700 Subject: [PATCH 205/251] Pass Java version in Windows launch info. PiperOrigin-RevId: 960880927 Change-Id: I9e0c3d0b5cc606d16beb2cec7779d45b4c4dc8ed --- java/bazel/rules/bazel_java_binary.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl index 716cde19..4b2a4b55 100644 --- a/java/bazel/rules/bazel_java_binary.bzl +++ b/java/bazel/rules/bazel_java_binary.bzl @@ -281,6 +281,7 @@ def _format_classpath_entry(runfiles_enabled, workspace_prefix, file): return "$(rlocation " + paths.normalize(workspace_prefix + file.short_path) + ")" def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, coverage_enabled, executable, coverage_main_class): + java_runtime_toolchain = semantics.find_java_runtime_toolchain(ctx) launch_info = ctx.actions.args().use_param_file("%s", use_always = True).set_param_file_format("multiline") launch_info.add("binary_type=Java") launch_info.add(ctx.workspace_name, format = "workspace_name=%s") @@ -291,7 +292,8 @@ def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jv launch_info.add(coverage_main_class, format = "jacoco_main_class=%s") launch_info.add_joined(classpath, map_each = _short_path, join_with = ";", format_joined = "classpath=%s", omit_if_empty = False) launch_info.add_joined(jvm_flags_for_launcher, join_with = "\t", format_joined = "jvm_flags=%s", omit_if_empty = False) - launch_info.add(semantics.find_java_runtime_toolchain(ctx).java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe") + launch_info.add(java_runtime_toolchain.java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe") + launch_info.add(java_runtime_toolchain.version, format = "java_version=%s") # TODO(b/295221112): Change to use the "launcher" attribute (only windows use a fixed _launcher attribute) launcher_artifact = ctx.executable._launcher From 526b1704315caed787777bb2ae8e231eb2520e22 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 10 Aug 2026 06:30:44 -0700 Subject: [PATCH 206/251] Remove usages of the Turbine graal native image for `darwin_x86_64` From https://www.graalvm.org/release-notes/JDK_25 : `Support for macOS x64 has been removed. Version 25.0.1 was the last release that supported this hardware architecture. GraalVM now only supports macOS on AArch64 (Apple Silicon).` Prepares for dropping it from the next `java_tools` release, which is currently broken after https://github.com/bazelbuild/bazel/pull/30228 PiperOrigin-RevId: 962117289 Change-Id: I5d33db28b2d3fa400f5ba73410a8486bb4a9ef20 --- toolchains/BUILD | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/toolchains/BUILD b/toolchains/BUILD index 25795555..920ae5f1 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -171,10 +171,6 @@ cc_library( actual = "@remote_java_tools_%s//:prebuilt_one_version" % OS, visibility = ["//visibility:private"], ), - alias( - name = "turbine_direct_graal_%s" % OS, - actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS, - ), ) for OS in [ "linux", @@ -185,6 +181,19 @@ cc_library( ] ] +[ + alias( + name = "turbine_direct_graal_%s" % OS, + actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS, + ) + for OS in [ + "linux", + "linux_aarch64", + "darwin_arm64", + "windows", + ] +] + alias( name = "ijar", actual = ":ijar_prebuilt_binary_or_cc_binary", @@ -278,7 +287,6 @@ alias( name = "turbine_direct_graal_or_java", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", - "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", @@ -290,7 +298,6 @@ alias( name = "turbine_direct_graal", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", - "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", From 3326e08f3f9a2dd1842e0899ab66f5cc06672ae6 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 10 Aug 2026 07:06:24 -0700 Subject: [PATCH 207/251] Fix rules_java `metadata.template.json` for BCR The `github_user_id` is now mandatory: https://buildkite.com/bazel/bcr-presubmit/builds/39168/table?jid=019febef-1d73-4158-9660-9cc6c02f9342&tab=output PiperOrigin-RevId: 962131561 Change-Id: I98d7f7180682b4f9d9e67f7c67d6a7e3b52a165d --- .bcr/metadata.template.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json index 9d091448..8ef2f6a7 100644 --- a/.bcr/metadata.template.json +++ b/.bcr/metadata.template.json @@ -4,7 +4,8 @@ { "email": "hvd@google.com", "github": "hvadehra", - "name": "Hemanshu Vadehra" + "name": "Hemanshu Vadehra", + "github_user_id": 2486163 } ], "versions": [], From 4e795085925f6f54a2e1199c4251e2be2fe1ca13 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Mon, 10 Aug 2026 11:11:56 -0700 Subject: [PATCH 208/251] Update Azul remotejdk versions (#370) Bump the remotejdk_21 pins from Zulu 21.46.19 (OpenJDK 21.0.9) to Zulu 21.52.15 (OpenJDK 21.0.12) for all six platforms. Zulu 21.0.9 lacks the backport of JDK-8341779 (reading type-use annotations on type-variable bounds from class files). This makes recent Error Prone report false positives such as NullArgumentForNonNullParameter on documented Guava API usage, e.g. Iterables.getFirst(iterable, null), when compiling with the Java 21 toolchain; see google/error-prone#5436 for the analysis by the Error Prone maintainers. Note that Azul changed the layout of the macOS tar.gz archives after 21.0.9: they now contain a macOS application bundle with the JDK under Contents/Home instead of a flat JDK image (the Zulu 25 macOS archives are still flat). The strip_prefix of the two macOS entries therefore descends into Contents/Home. SHA-256 checksums are taken from the Azul metadata API; the linux_x64 and macosx_x64 artifacts were additionally downloaded and verified locally. Fixes #369 Closes #370 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/370 from davido:bump-remotejdk21-21.0.12 c1f5a676d75d2c94a91d1f89157c2d062f97c42b PiperOrigin-RevId: 962258547 Change-Id: Ifaf5f4f8a9804e1303fbe10e89e49baac7c06dec --- java/bazel/BUILD.bazel | 6 +- java/bazel/repositories_util.bzl | 25 +++-- java/repositories.bzl | 179 ++++++++++++++++--------------- test/check_remote_jdk_configs.sh | 9 +- 4 files changed, 122 insertions(+), 97 deletions(-) diff --git a/java/bazel/BUILD.bazel b/java/bazel/BUILD.bazel index f3c47cf7..dcf657ab 100644 --- a/java/bazel/BUILD.bazel +++ b/java/bazel/BUILD.bazel @@ -27,7 +27,7 @@ genrule( echo > $@ while read -r config; do TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX) - IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config" + IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url patch_cmds <<< "$$config" echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr curl --retry 5 --write-out '%{{onerror}}%{{url}}\n' --show-error --silent --fail -o $$TMP_FILE -L "$$primary_url" > /dev/stderr sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1` @@ -38,6 +38,9 @@ while read -r config; do echo " strip_prefix = \\"$$strip_prefix\\"," echo " urls = $$urls," echo " version = \\"$$version\\"," + if [[ "$$patch_cmds" != "[]" ]]; then + echo " patch_cmds = $$patch_cmds," + fi echo ")," rm -f "$$TMP_FILE" done <<< '{configs}' >> $@ @@ -49,6 +52,7 @@ done <<< '{configs}' >> $@ config.strip_prefix, json.encode(config.target_compatible_with), config.urls[0], + json.encode(config.patch_cmds), ]) for config in FLAT_CONFIGS ])), diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl index 40101d37..813f5f13 100644 --- a/java/bazel/repositories_util.bzl +++ b/java/bazel/repositories_util.bzl @@ -18,7 +18,7 @@ visibility(["//test"]) _RELEASE_CONFIGS = { "8": { "zulu": { - "release": "8.90.0.19-ca-jdk8.0.472", + "release": "8.96.0.19-ca-jdk8.0.502", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -34,7 +34,7 @@ _RELEASE_CONFIGS = { }, "11": { "zulu": { - "release": "11.84.17-ca-jdk11.0.29", + "release": "11.90.19-ca-jdk11.0.32", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -56,7 +56,7 @@ _RELEASE_CONFIGS = { }, "17": { "zulu": { - "release": "17.62.17-ca-jdk17.0.17", + "release": "17.68.17-ca-jdk17.0.20", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -72,7 +72,7 @@ _RELEASE_CONFIGS = { }, "21": { "zulu": { - "release": "21.46.19-ca-jdk21.0.9", + "release": "21.52.15-ca-jdk21.0.12", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -88,7 +88,7 @@ _RELEASE_CONFIGS = { }, "25": { "zulu": { - "release": "25.32.17-ca-jdk25.0.2", + "release": "25.36.15-ca-jdk25.0.4", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -135,7 +135,16 @@ def _zulu_remote_jdk_repo(os, cpu, release): "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] - return urls, archive_name + patch_cmds = [] + if os == "macos": + # Recent Zulu macOS archives are application bundles: the JDK lives + # under Contents/Home and the top-level bin/lib/... symlinks that + # earlier releases shipped are gone. strip_prefix stays at the + # archive root (uniform with the other platforms); recreate the + # top-level symlinks so the shared JDK BUILD template still finds + # bin/, lib/, etc. + patch_cmds = ["ln -s Contents/Home/* ."] + return urls, archive_name, patch_cmds def _adoptium_linux_remote_jdk_repo(version, cpu, release): os = "linux" @@ -173,8 +182,9 @@ def _flatten_configs(): for os, cpus in distrib_cfg["platforms"].items(): for cpu in cpus: name = _name_for_remote_jdk(version, os, cpu) + patch_cmds = [] if distrib == "zulu": - urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release) + urls, strip_prefix, patch_cmds = _zulu_remote_jdk_repo(os, cpu, release) elif distrib == "adoptium": if os != "linux": fail("adoptium jdk configured but not linux") @@ -193,6 +203,7 @@ def _flatten_configs(): urls = urls, strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix), target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu], + patch_cmds = patch_cmds, )) return result diff --git a/java/repositories.bzl b/java/repositories.bzl index df95f86d..569bd679 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -86,41 +86,43 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remote_jdk8_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "c372fb26480c052537125013cb0ba7336c404e5190ea8f6e2de247b676432a67", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz"], + sha256 = "b23296caf10d0c3db054d4a58b9dd168976991472f2203335d7c4820f98c4a4e", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "6f9e3fa773829ac2553411fb0cdeb394980627c47c9ab8f8892d4b917b70e2dd", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz"], + sha256 = "5923daaf12fd0b87e60e437aaae7b2e5b257846cdb8ac15065258fb59a1da70a", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_x64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "823d547ab9508e3a2b8abd3c5de66a39a50a254dc5835747cf3c2617fbe55600", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz"], + sha256 = "9f9e5038c638e415e507e8b5118a774822f553a56e76bdf4b042c3fbe7b69083", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64.tar.gz"], version = "8", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remote_jdk8_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "96fb7bc3a2babd7f807484b1b8f1dfb8cf2c61ea27b2d0630e2237088b0a5100", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz"], + sha256 = "b29088ddb00f81db1e01d6d5bfddd44a58e46ef44b50c372cff3eb1bf5b23173", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_x64.tar.gz"], version = "8", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remote_jdk8_windows", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "ff90484103d3fdb9808f737af027586c8dbfa1aa8a310ce99b0b5e0517567aee", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip"], + sha256 = "0d64e817ba56962d447339040f9e7bd1119f98b813d0a968e3485aab0c530a47", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-win_x64.zip"], version = "8", ), struct( @@ -134,41 +136,43 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk11_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "5a225a0fe0a92bc6c04c8c5aeb03c697c6fd114465829f23e494a2ad44fa1cc0", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz"], + sha256 = "31fb32a1c9d842f96e8e79c683996e217d087b3aeac0cc6bfc39f028eb860146", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_aarch64.tar.gz"], version = "11", ), struct( name = "remotejdk11_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "681b2e4bf7fedf4d20666fc2a954b83ff5675ccfb916c867267d29c85c2ee310", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz"], + sha256 = "d4832d97886444346ed75fd1059c68c5e38795098e3273e4a0929fe2eb2abf76", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_x64.tar.gz"], version = "11", ), struct( name = "remotejdk11_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "09ed1734c2d88fadcb75fdbec1ba5467d32e7fa2b10894541aa8e3d3ce78dc2d", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz"], + sha256 = "a552338385fa27026ced01a3c56a3b3a2de048ed4b79907d876e99be80547551", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_aarch64.tar.gz"], version = "11", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk11_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "b7f5a37c47ed94af1c8ecf631b1dc6dec990958f3afd4222a7dd27d6ca1084bd", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz"], + sha256 = "5ba1b39cc08999645944bcfd54da48dd6c9a0891785d56cff95e92324fa841f6", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_x64.tar.gz"], version = "11", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk11_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "f4002a8090662ff66bf9f3248604be0f9d226e964085bd59bbea4b8535df3de1", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip"], + sha256 = "700a42d5764b5f41ab43adbfe3e03deac329cc10886f2312a5908fd5a3c78d46", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-win_x64.zip"], version = "11", ), struct( @@ -198,49 +202,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk17_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "527b76fbd60e8f9644f6b70800d15160cdbd3344bc6fbf30d42e905f540a770c", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz"], + sha256 = "46f1dc7678760d37d38699c5a5a34dea8ed451dcdf6d27890a7b61f025e7ff60", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_aarch64.tar.gz"], version = "17", ), struct( name = "remotejdk17_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "1dcbbed73e95dc35f5c60402a84936f6830ff43c2a0dc0037a5657dbc25472c1", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz"], + sha256 = "32c5efedf69f4a95635ea2923f6a6ee90ce6ca83df0bd43ba55dd662d5af429a", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_x64.tar.gz"], version = "17", ), struct( name = "remotejdk17_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "5558f7efe6297ecb20f422f31471555cd43e9499beb304b8f3ddc68796d2874b", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz"], + sha256 = "0da52534760b74ba8a42660384b2f4e44311a47ae52faa45fcbd829b2797b244", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_aarch64.tar.gz"], version = "17", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk17_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "e6b2fb0cd3f929225a179c2fb2813abd1834f839a3b4c8cdcb36067aa16b6f83", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz"], + sha256 = "b5bace4a346a7af0fe4f50904c46770e66d4b465800b038693c35e5d5b9bd52a", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_x64.tar.gz"], version = "17", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk17_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "c1bba9148907348da93b0de2c9abd56bd180efcb6b1f35068ab9785015fcd74b", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip"], + sha256 = "e125b3b64c9b5a0a2f2737e4a94ba275b541d8cc85d61c95ff875a3463ce0d8e", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_aarch64.zip"], version = "17", ), struct( name = "remotejdk17_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "bd8a942bb543f109a28d3eadf3ec2f29a3ee28ab53506e31d2858292f63c6949", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip"], + sha256 = "d207d8cec299f4d216bef1c7c081ba9504e79ba1cbc740de312d4a91b2d46436", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_x64.zip"], version = "17", ), struct( @@ -262,49 +268,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk21_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "a826a93c18d4388ec8d5d4057f5bb1b5c60f00ffc875ed299dea17aa947555ee", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz"], + sha256 = "dc7ed9ab7dfd33f2ddb1cd8311d3b00738497961a420533d81088051eac3f195", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_aarch64.tar.gz"], version = "21", ), struct( name = "remotejdk21_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "67e810b31427ac0ff1c249473595066a00bdf0f9265df186c32905d5f75c93b8", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz"], + sha256 = "b1a9df12e798770d1b2db43b402a80f1e6080cff6d5d1d1fbe5c768fb4225f6a", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_x64.tar.gz"], version = "21", ), struct( name = "remotejdk21_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "b56112ad12d3dfe62802840655ecf198fe4ca48729824c939d65a69e803536c7", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz"], + sha256 = "84d38c4bf04f73d585bd319b949758d00abde50149a9522c2d9deef46b9a3ec6", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_aarch64.tar.gz"], version = "21", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk21_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "3d870d823e3e101189b00ad975188c0321e31056ac8ca8b487bcf4454f3b5cfe", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz"], + sha256 = "14e05cb1299c27cd26d3c5c6815723f63018df548dc7278c810767607902b4f4", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_x64.tar.gz"], version = "21", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk21_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "1210b169db7b40d7305a94d41ab3eb87aaee51108b43f8f7f36f0c2865107790", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip"], + sha256 = "d75658d371e025bb6378231551b4d53d1f5312cb0fccf7aa3b039d91ce1f0b7e", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_aarch64.zip"], version = "21", ), struct( name = "remotejdk21_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "0c9812c0fe527b59f48c70cb527035c8a7abe620b31f776b4ddc21bddc1cd067", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip"], + sha256 = "3c06e6693fd6fa725b985e66798a6a8293c75f52b793490754ad3c54d3d8b5a6", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_x64.zip"], version = "21", ), struct( @@ -334,49 +342,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk25_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "f7295abb1decb2f6e0ea9f760a70917f2d47356db4366d615c7ab9b01c3c6866", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz"], + sha256 = "ae04e25b16116ddd0f72cb387742d5122bb29c4b94f0fed08ff2bccc395f9daa", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_aarch64.tar.gz"], version = "25", ), struct( name = "remotejdk25_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "f1752d0051b6ca233625ddb2c18c9170edbe55c5ee6515bfefd8ea0197ee1c20", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz"], + sha256 = "e476f5c98952cb365ca77a814dbe3c74341e71ae76d1a87d1c0a69c7d2b1b2d0", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_x64.tar.gz"], version = "25", ), struct( name = "remotejdk25_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "537ac74fa1ca2c4dd8f6063ddede0138ae4a896f128bfe10b428a7dcc4aa929f", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz"], + sha256 = "c422f22713510992c764a7d577ae4f5add223529ab356993f38f8df2d4b247bd", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_aarch64.tar.gz"], version = "25", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk25_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "fe22346c192920c5b84b23f4aa24e3debb0bb94fc428016f7c2b2c7790c82780", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz"], + sha256 = "63273c6b9e2d9b250a0009ffdaa6d9f27af6ba98772516c391276106fb9f2820", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_x64.tar.gz"], version = "25", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk25_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "5f44792a12af2100b4db9b5120c27c42af8080ad63bc9eaadc9ca25e5c7dd590", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip"], + sha256 = "2e8468229aea447152343fff87dbebe5c339e1fbab143a8f227f6b2f388c0a8c", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_aarch64.zip"], version = "25", ), struct( name = "remotejdk25_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "90bcbbcbe2fb7aec43ce8fd2efa024fcc48f00bbdcd7a76b58f912d6b97e6d56", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip"], + sha256 = "a91265f0f0fb40155befe8f1cae7d1a0ae2ab4b7760f52733160d206637b50d1", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_x64.zip"], version = "25", ), struct( @@ -425,6 +435,7 @@ def _remote_jdk_repos_for_version(version): strip_prefix = item.strip_prefix, urls = item.urls, version = item.version, + patch_cmds = getattr(item, "patch_cmds", []), ) def remote_jdk8_repos(name = ""): diff --git a/test/check_remote_jdk_configs.sh b/test/check_remote_jdk_configs.sh index cea093c0..e7f27201 100755 --- a/test/check_remote_jdk_configs.sh +++ b/test/check_remote_jdk_configs.sh @@ -36,15 +36,14 @@ for config in "$@"; do fail "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" fi if [[ -z "${url##*.tar.gz}" ]]; then - bin_dir=$(tar ztf ${TMP_FILE} | egrep '/bin(|/)$' | sort | head -n1) + root_dir=$(tar ztf ${TMP_FILE} --exclude='*/*') elif [[ -z "${url##*.zip}" ]]; then - bin_dir=$(unzip -Z1 ${TMP_FILE} | egrep '/bin(|/)/$' | sort | head -n1) + root_dir=$(unzip -Z1 ${TMP_FILE} | head -n1) else fail "ERROR: unexpected archive type for ${name}" fi - root_dir="${bin_dir%/bin*}" - if [ "${root_dir}" != "${strip_prefix}" ]; then - fail "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}, got: ${root_dir}" + if [ "${root_dir}" != "${strip_prefix}/" ]; then + fail "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" fi if [[ -n "${mirror_url}" ]]; then debug_log "checking mirror: ${mirror_url}" From e88b808858159d788bc71509d637aabefc9cc9da Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 11 Aug 2026 03:08:12 -0700 Subject: [PATCH 209/251] Update `java_tools` to `v20.0` Work towards https://github.com/bazelbuild/rules_java/issues/371 PiperOrigin-RevId: 962673909 Change-Id: I315705e81361db38e076804324ea77b52ff616c4 --- java/repositories.bzl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/java/repositories.bzl b/java/repositories.bzl index 569bd679..aa7a77c9 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,39 +22,39 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v19.0", - "source_revision": "61972bfd7fb6f587fc4576b5114e20758b501806", + "version": "v20.0", + "source_revision": "5dc60cedd5456112b1c21c577f94c041230be3ff", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux-v19.0.zip", - "sha": "7d5b0c01f99ea5596b7901a7e5f9173f3ae3c4f0b480378e87567eaf97d75d25", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_linux-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_linux-v20.0.zip", + "sha": "3a64dd096053cf6b59b01f4485d834ad03cece23584cc50ba9c09687b14a24cc", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux_aarch64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux_aarch64-v19.0.zip", - "sha": "34b14fdfe8d6e32ed7f80e7c4d34ce79f4006e0d4b621552f507e51b9d6a3d7d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_linux_aarch64-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_linux_aarch64-v20.0.zip", + "sha": "2b747db98949378d0108b22719f5edafb5178da9042c3652262c585485a4f655", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_windows-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_windows-v19.0.zip", - "sha": "86c5a58ccefdb9e704fddd325f5fbc7867b2cdd128fb8b9abfdf607a75d2ae71", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_windows-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_windows-v20.0.zip", + "sha": "90cef5c21481f5fce08cbf655cd29b9534474c104d350f503578ac88eb006fe5", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_x86_64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_x86_64-v19.0.zip", - "sha": "78ff8ec7038ab5f9cd261cdf9ff75ea0eb2af7579f9aeef9d658459ee37fabac", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_darwin_x86_64-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_darwin_x86_64-v20.0.zip", + "sha": "9722b76d932f7dcf777cad779d5108a45af306a70e4ae736cf18096b580411eb", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_arm64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_arm64-v19.0.zip", - "sha": "86f15280dd0ce121a22f061e2e301ecf746597caa4938cf56852b3d311b830d8", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_darwin_arm64-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_darwin_arm64-v20.0.zip", + "sha": "fc66d59d6da440f2aacf399b2fb86ce0ef00675aa6c7e407f93d669bc85b4b09", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools-v19.0.zip", - "sha": "d21d4aad1a18062512bcf4e8f7a09a4f5a042c760daa779e0ddda6e41b170507", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools-v20.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools-v20.0.zip", + "sha": "ffcc2e99395f2931d86f85de453e592393de75d8276a00bf5c1ccf983a61bf0f", }, }, } From 693659a45100ea819f6c7f11270e01c8dc8c5bb7 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 11 Aug 2026 04:44:50 -0700 Subject: [PATCH 210/251] Add Bazel 9.x to `rules_java`'s BCR presubmits PiperOrigin-RevId: 962709107 Change-Id: I10c28029b1303d6677d153456d66d356a46fa329 --- .bcr/presubmit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 26dad0fe..6d221348 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -8,6 +8,7 @@ matrix: bazel: - 7.x - 8.x + - 9.x tasks: verify_build_targets: name: "Verify build targets w/ Bazel {bazel}" From 7f7a7ba54227d03b4789acf0feb8f605035f3b95 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 17 Aug 2026 04:47:02 -0700 Subject: [PATCH 211/251] Add a test for `java_binary` jdeps output filename. (ignore-relnotes) PiperOrigin-RevId: 965894949 Change-Id: If9dcc5b0e131e87f159d90056c36a2aed8f36b18 --- test/java/common/rules/java_binary_tests.bzl | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 9bb7fa85..496a0053 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -489,6 +489,26 @@ def _test_java_binary_duplicate_classpath_resources_impl(env, target): matching.str_matches("entries must have different file names (duplicate: same.txt)"), ) +def _test_java_binary_jdeps(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + resources = ["app.properties"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_jdeps_impl, + target = name + "/app", + ) + +def _test_java_binary_jdeps_impl(env, target): + # should produce an app.jdeps file, not an app-class.jdeps file. + env.expect.that_target(target).action_generating("{package}/{name}-class.jar").contains_flag_values([ + ("--output_deps_proto", "{bindir}/{package}/{name}.jdeps"), + ]) + def java_binary_tests(name): test_suite( name = name, @@ -506,5 +526,6 @@ def java_binary_tests(name): _test_java_binary_java_package, _test_java_binary_rule_in_sub_directory, _test_java_binary_duplicate_classpath_resources, + _test_java_binary_jdeps, ], ) From 201e09dd3e45eb072457623e96e1f60fc8d8e5fd Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 20 Aug 2026 02:44:06 -0700 Subject: [PATCH 212/251] Improve the `javac_action_subject` API - Make `strict_java_deps` return a string subject - Make `direct_dependencies` return an empty list if the flag was unset - Make the `output` parameter optional while constructing the subject, default to looking up the action by mnemonic. - Add an optional `desc` parameter - helpful to distinguish between the same target built in different configurations. (ignore-relnotes) PiperOrigin-RevId: 967690792 Change-Id: I6f90a4a1b3a06022e8306a3f78984de51a4b97c9 --- test/java/common/rules/java_library_tests.bzl | 2 +- test/java/testutil/javac_action_subject.bzl | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index 4115b121..ec5500ce 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -337,7 +337,7 @@ def _test_strict_java_deps_impl(env, target): # javac action's argv at all; the "OFF" value (which is equivalent to an unset flag) in that # case is injected by javac_action_subject for convenience and canonicalization. expect_that_javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") - expect_that_javac_action.strict_java_deps().contains_exactly([env.ctx.attr.expected_strict_java_deps]) + expect_that_javac_action.strict_java_deps().equals(env.ctx.attr.expected_strict_java_deps) def _test_strict_java_deps_off(name): _test_strict_java_deps(name, "OFF") diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index a887d689..794f35a7 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -1,15 +1,19 @@ """Bespoke rules_testing subject for the Java compilation action""" -load("@rules_testing//lib:truth.bzl", "subjects", "truth") +load("@rules_testing//lib:truth.bzl", "subjects") load("@rules_testing//lib:util.bzl", "TestingAspectInfo") -def _new_javac_action_subject(env, target, output): - action_subject = env.expect.that_target(target).action_generating(output) +def _new_javac_action_subject(env, target, output = None, desc = ""): + target_subject = env.expect.that_target(target) + if output: + action_subject = target_subject.action_generating(output) + else: + action_subject = target_subject.action_named("Javac") self = struct( actual = action_subject.actual, parsed_flags = _parse_flags(action_subject.actual.argv), - meta = truth.expect(env).meta.derive( - "Javac", + meta = target_subject.meta.derive( + desc + ".Javac", format_str_kwargs = { "name": target.label.name, "package": target.label.package, @@ -19,12 +23,12 @@ def _new_javac_action_subject(env, target, output): ) public = struct( - direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), + direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta, default = []), deps_artifacts = lambda: _create_subject_for_flag("--deps_artifacts", self.parsed_flags, self.meta), javacopts = lambda: _create_subject_for_flag("--javacopts", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), # An unset --strict_java_deps is equivalent to "OFF". - strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]), + strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]).offset(0, factory = subjects.str), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), resources = lambda: _create_subject_for_flag("--resources", self.parsed_flags, self.meta), classpath = lambda: _create_subject_for_flag("--classpath", self.parsed_flags, self.meta), From b39810e07ea3f484c63a3d6ca8ba9b2fc6c08530 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 21 Aug 2026 01:20:47 -0700 Subject: [PATCH 213/251] Remove `java_attrs.resources` This was only ever added to the inputs of the deploy jar action but not passed on the command line so effectively unused. (ignore-relnotes) PiperOrigin-RevId: 968340782 Change-Id: I3878d622095cf72d245dcff0cf1de25dcb53d081 --- java/common/rules/impl/BUILD | 1 - java/common/rules/impl/java_binary_deploy_jar.bzl | 5 ----- java/common/rules/impl/java_binary_impl.bzl | 10 ---------- 3 files changed, 16 deletions(-) diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index 70adeccd..a6eb44ba 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -21,7 +21,6 @@ bzl_library( deps = [ ":java_helper_bzl", "//java/common:proguard_spec_info_bzl", - "@com_google_protobuf//bazel/common:proto_info_bzl", "@rules_cc//cc/common:cc_helper_bzl", ], ) diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index d6add141..2600e4e2 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -69,7 +69,6 @@ def create_deploy_archives( launcher_info.launcher, main_class, coverage_main_class, - java_attrs.resources, classpath_resources, runtime_classpath, manifest_lines, @@ -91,7 +90,6 @@ def create_deploy_archives( launcher_info.unstripped_launcher, main_class, coverage_main_class, - java_attrs.resources, classpath_resources, runtime_classpath, manifest_lines, @@ -112,7 +110,6 @@ def create_deploy_archive( launcher, main_class, coverage_main_class, - resources, classpath_resources, runtime_classpath, manifest_lines, @@ -135,7 +132,6 @@ def create_deploy_archive( launcher: (File) the launcher artifact main_class: (String) FQN of the entry point for execution coverage_main_class: (String) FQN of the entry point for coverage collection - resources: (Depset) resource inputs classpath_resources: (Depset) classpath resource inputs runtime_classpath: (Depset) source files to add to the jar build_target: (String) Name of the build target for stamping @@ -155,7 +151,6 @@ def create_deploy_archive( input_files.extend(build_info_files) transitive_input_files = [ - resources, classpath_resources, runtime_classpath, ] diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 8b9b68de..13718eb8 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -14,7 +14,6 @@ """ Implementation of java_binary for bazel """ -load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") @@ -300,13 +299,6 @@ def _collect_attrs(ctx, runtime_classpath, classpath_resources): runtime_classpath_for_archive = get_runtime_classpath_for_archive(runtime_classpath, deploy_env_jars) runtime_jars = [ctx.outputs.classjar] - resources = [p for p in ctx.files.srcs if p.extension == "properties"] - transitive_resources = [] - for r in ctx.attr.resources: - transitive_resources.append( - r[ProtoInfo].transitive_sources if ProtoInfo in r else r.files, - ) - resource_names = dict() for r in classpath_resources: if r.basename in resource_names: @@ -318,7 +310,6 @@ def _collect_attrs(ctx, runtime_classpath, classpath_resources): runtime_classpath_for_archive = runtime_classpath_for_archive, classpath_resources = depset(classpath_resources), runtime_classpath = depset(order = "preorder", direct = runtime_jars, transitive = [runtime_classpath]), - resources = depset(resources, transitive = transitive_resources), ) def _generate_coverage_manifest(ctx, output, runtime_classpath): @@ -455,7 +446,6 @@ def _auto_create_deploy_jar(ctx, info, launcher_info, main_class, coverage_main_ launcher = launcher_info.launcher, main_class = main_class, coverage_main_class = coverage_main_class, - resources = java_attrs.resources, classpath_resources = java_attrs.classpath_resources, runtime_classpath = runtime_classpath, manifest_lines = [], From ec0e90c370471fa75b487b6cce63479934475e08 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 21 Aug 2026 01:46:59 -0700 Subject: [PATCH 214/251] Add a `java_toolchain` attribute to specify options to the `header_compiler_direct` tool (#375) Primary motivation is to let users not using the Turbine graal native image silence protobuf sun.misc.Unsafe warnings from the direct header compiler turbine_direct (header_compiler_direct) bundles protobuf, whose UnsafeUtil calls terminally-deprecated sun.misc.Unsafe methods. On JDK 24+ (JEP 498) the JVM prints a warning for each such call during header compilation: WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.protobuf.UnsafeUtil (.../java_tools/turbine_direct_binary_deploy.jar) Unlike the Turbine worker, header_compiler_direct does not receive turbine_jvm_opts, and --jvmopt does not reach header-compilation actions, so a toolchain currently has no way to silence these warnings for the direct header compiler. Add --sun-misc-unsafe-memory-access=allow to header_compiler_direct_jvm_opts, gated on the runtime feature version since the flag is rejected on JDK <= 22. See https://github.com/protocolbuffers/protobuf/issues/20760. Fixes #374 Closes #375 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/375 from davido:turbine-direct-unsafe-memory-access da635b6bebb7ac660f19451469182f54adea884c PiperOrigin-RevId: 968352943 Change-Id: I94d5bc5d564016ced3cc3b6e06330fad4d8451a7 --- java/common/rules/java_toolchain.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index a24ae4f1..a635c5dd 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -91,6 +91,9 @@ def _java_toolchain_impl(ctx): else: header_compiler_direct_data = [] header_compiler_direct_jvm_opts = [] + + header_compiler_direct_jvm_opts = header_compiler_direct_jvm_opts + ctx.attr.header_compiler_direct_opts + if ctx.attr.oneversion_allowlist and ctx.attr.oneversion_whitelist: fail("oneversion_allowlist and oneversion_whitelist are mutually exclusive") oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist @@ -588,6 +591,18 @@ Labels of data available for label-expansion in turbine_jvm_opts. The list of arguments for the JVM when invoking turbine. """, ), + "header_compiler_direct_opts": attr.string_list( + doc = """ +Additional options passed to the direct header compiler, verbatim and without +location or make-variable expansion. + +Warning: these are only meaningful when the direct header compiler runs on a +JVM, such as TurbineDirect's deploy jar. A native direct header compiler such +as turbine_direct_graal parses them as Turbine command-line options, so do not +set JVM options (for example --sun-misc-unsafe-memory-access=allow) when a +native direct header compiler is in use. + """, + ), "xlint": attr.string_list( default = [], doc = """ From 40be191083451bcb8895464a88f233267f3219c0 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 24 Aug 2026 07:48:43 -0700 Subject: [PATCH 215/251] Add a test for `java_binary` `--experimental_strict_java_deps` behavior (ignore-relnotes) PiperOrigin-RevId: 969850063 Change-Id: I150c001164ecbdd09e1a6411fb2a1ee47bb4715a --- .../common_launcher_java_binary_tests.bzl | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index dc3d18d5..877f3d45 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -1,5 +1,6 @@ """Parameterized tests for java_binary with --java_launcher""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") @@ -10,6 +11,8 @@ load("//java:java_test.bzl", "java_test") load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") load("//test/java/testutil:binary_executable_subject.bzl", "expect_that_executable") +load("//test/java/testutil:helper.bzl", "always_passes") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") def _test_java_binary_non_executable_rule_outputs(name): @@ -316,6 +319,79 @@ def _test_java_test_inner_class_impl(env, target): expected = "'Outer$Inner'" # shell-quoted expect_that_executable.of_target(env, target).test_suite().equals(expected) +def _test_java_binary_strict_java_deps_flag(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + deps = [ + name + "/alpha", + name + "/bravo", + ], + ) + util.helper_target( + java_library, + name = name + "/alpha", + srcs = ["Alpha.java"], + ) + util.helper_target( + java_library, + name = name + "/bravo", + srcs = ["Bravo.java"], + exports = [name + "/delta"], + deps = [name + "/charlie"], + ) + util.helper_target( + java_library, + name = name + "/charlie", + srcs = ["Charlie.java"], + ) + util.helper_target( + java_library, + name = name + "/delta", + srcs = ["Delta.java"], + ) + + analysis_test( + name = name, + attrs = { + "off": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "OFF"}}, + "warn": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "WARN"}}, + "error": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "ERROR"}}, + "strict": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "STRICT"}}, + }, + impl = _test_java_binary_strict_java_deps_flag_impl, + targets = { + "off": name + "/app", + "warn": name + "/app", + "error": name + "/app", + "strict": name + "/app", + }, + ) + +def _test_java_binary_strict_java_deps_flag_impl(env, targets): + # off + assert_that_javac = javac_action_subject.of(env, targets.off, desc = "off") + assert_that_javac.direct_dependencies().contains_exactly([]) + assert_that_javac.strict_java_deps().equals("OFF") + + for mode, target, expected_flag_value in [ + ("WARN", targets.warn, "WARN"), + ("ERROR", targets.error, "ERROR"), + ("STRICT", targets.strict, "ERROR"), + ]: + assert_that_javac = javac_action_subject.of(env, target, desc = "mode=" + mode) + assert_that_javac.strict_java_deps().equals(expected_flag_value) + assert_that_javac.direct_dependencies().contains_exactly([ + "{bindir}/{package}/lib{test_name}/alpha-hjar.jar", + "{bindir}/{package}/lib{test_name}/bravo-hjar.jar", + "{bindir}/{package}/lib{test_name}/delta-hjar.jar", + ]).in_order() + def java_binary_launcher_tests(name): test_suite( name = name, @@ -332,5 +408,6 @@ def java_binary_launcher_tests(name): _test_java_binary_native_library_path_includes_transitive_deps, _test_java_binary_inner_class, _test_java_test_inner_class, + _test_java_binary_strict_java_deps_flag, ], ) From 59e77d1d2b00cde7f4592201ae6e30d0278071c2 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 24 Aug 2026 08:21:44 -0700 Subject: [PATCH 216/251] Update `java_tools` `v21.0` Work towards https://github.com/bazelbuild/rules_java/issues/378 PiperOrigin-RevId: 969865064 Change-Id: Ib44203e77fb705a7e6ddc4c2b95d6d1f81131721 --- java/repositories.bzl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/java/repositories.bzl b/java/repositories.bzl index aa7a77c9..007d934c 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,39 +22,39 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v20.0", - "source_revision": "5dc60cedd5456112b1c21c577f94c041230be3ff", + "version": "v21.0", + "source_revision": "1ec21d9228a9b0aad0acfbf812f62e13f6addb88", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_linux-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_linux-v20.0.zip", - "sha": "3a64dd096053cf6b59b01f4485d834ad03cece23584cc50ba9c09687b14a24cc", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_linux-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_linux-v21.0.zip", + "sha": "cf585d7dddf524672815bb09d92bcc8a54f55e5ee7b7e5c862756b6e5ef1be1d", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_linux_aarch64-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_linux_aarch64-v20.0.zip", - "sha": "2b747db98949378d0108b22719f5edafb5178da9042c3652262c585485a4f655", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_linux_aarch64-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_linux_aarch64-v21.0.zip", + "sha": "e44592d23b88a6773f558a7b19437f42d3fe72cef02a2d3da591c0e304b5cc8d", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_windows-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_windows-v20.0.zip", - "sha": "90cef5c21481f5fce08cbf655cd29b9534474c104d350f503578ac88eb006fe5", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_windows-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_windows-v21.0.zip", + "sha": "6dc3eba1567b700622e77523af397a9d2fb314706243318981459a1e980abe3a", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_darwin_x86_64-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_darwin_x86_64-v20.0.zip", - "sha": "9722b76d932f7dcf777cad779d5108a45af306a70e4ae736cf18096b580411eb", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_darwin_x86_64-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_darwin_x86_64-v21.0.zip", + "sha": "b90f87567c542fae93d2c24bfe65c01ae3c06b236926df863a70b0a99202f2e4", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools_darwin_arm64-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools_darwin_arm64-v20.0.zip", - "sha": "fc66d59d6da440f2aacf399b2fb86ce0ef00675aa6c7e407f93d669bc85b4b09", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_darwin_arm64-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_darwin_arm64-v21.0.zip", + "sha": "fcac51b9198e16bb0f3eaa583efc584cb87df9c22eb637b3e64a54d2998653ca", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v20.0/java_tools-v20.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v20.0/java_tools-v20.0.zip", - "sha": "ffcc2e99395f2931d86f85de453e592393de75d8276a00bf5c1ccf983a61bf0f", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools-v21.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools-v21.0.zip", + "sha": "a0017111e49727f54e7e0d684e69735d3ac79abe933de2aef8577b2808cbbe46", }, }, } From 97d85d1b8d494fc0d613b2a78a8a8923fde7b1d3 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Tue, 25 Aug 2026 02:18:16 -0700 Subject: [PATCH 217/251] Remove header_compiler_direct_opts from java_toolchain (#379) java_tools v21.0 bundles protobuf 36.0, whose Java runtime no longer uses sun.misc.Unsafe for standard generated code. That removes the JDK 24+ warning that motivated header_compiler_direct_opts as a TurbineDirect workaround. Drop the attribute before it becomes API surface. The direct header compiler no longer needs --sun-misc-unsafe-memory-access=allow for protobuf. A native turbine_direct_graal would also treat JVM flags passed through this attribute as Turbine command-line options. Fixes #374 RELNOTES: None Closes #379 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/379 from davido:revert-header-compiler-direct-opts eec72e458f6804ed52a699a92f82a5d52aca0693 PiperOrigin-RevId: 970407219 Change-Id: I30b00796fd175de88d05477fe9cc67a3cce5a2c7 --- java/common/rules/java_toolchain.bzl | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index a635c5dd..a24ae4f1 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -91,9 +91,6 @@ def _java_toolchain_impl(ctx): else: header_compiler_direct_data = [] header_compiler_direct_jvm_opts = [] - - header_compiler_direct_jvm_opts = header_compiler_direct_jvm_opts + ctx.attr.header_compiler_direct_opts - if ctx.attr.oneversion_allowlist and ctx.attr.oneversion_whitelist: fail("oneversion_allowlist and oneversion_whitelist are mutually exclusive") oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist @@ -591,18 +588,6 @@ Labels of data available for label-expansion in turbine_jvm_opts. The list of arguments for the JVM when invoking turbine. """, ), - "header_compiler_direct_opts": attr.string_list( - doc = """ -Additional options passed to the direct header compiler, verbatim and without -location or make-variable expansion. - -Warning: these are only meaningful when the direct header compiler runs on a -JVM, such as TurbineDirect's deploy jar. A native direct header compiler such -as turbine_direct_graal parses them as Turbine command-line options, so do not -set JVM options (for example --sun-misc-unsafe-memory-access=allow) when a -native direct header compiler is in use. - """, - ), "xlint": attr.string_list( default = [], doc = """ From 8f847aa0ea2221ede4625696551d62c42627cb3d Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Tue, 25 Aug 2026 05:56:47 -0700 Subject: [PATCH 218/251] Allow java_binary to exclude build metadata (#376) When enabled, omit build-info inputs and pass `--exclude_build_data` to singlejar. Reject explicit stamping with build data excluded. Closes #376 COPYBARA_INTEGRATE_REVIEW=No public description PiperOrigin-RevId: 970499598 Change-Id: I79bac9327c7f6637ad2ba5f54db18e47d1907c5f --- java/bazel/rules/bazel_java_binary.bzl | 8 +++ .../rules/impl/java_binary_deploy_jar.bzl | 20 ++++-- test/java/bazel/rules/java_binary_tests.bzl | 64 +++++++++++++++++++ test/java/common/rules/java_binary_tests.bzl | 3 + 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl index 4b2a4b55..0611e062 100644 --- a/java/bazel/rules/bazel_java_binary.bzl +++ b/java/bazel/rules/bazel_java_binary.bzl @@ -122,6 +122,7 @@ def bazel_base_binary_impl(ctx, is_test_rule_class): main_class, coverage_main_class, info.strip_as_default, + exclude_build_data = ctx.attr.exclude_build_data, add_exports = info.add_exports, add_opens = info.add_opens, ) @@ -346,6 +347,13 @@ def make_binary_rule(implementation, *, doc, attrs, executable = False, test = F BASE_BINARY_ATTRS = merge_attrs( BASIC_JAVA_BINARY_ATTRIBUTES, { + "exclude_build_data": attr.bool( + default = False, + doc = """ +Whether to omit the build-data.properties file from the +*_deploy.jar output. + """, + ), "resource_strip_prefix": attr.string( doc = """ The path prefix to strip from Java resources. diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index 2600e4e2..b315bc35 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -32,7 +32,8 @@ def create_deploy_archives( one_version_level = "OFF", one_version_allowlist = None, extra_args = [], - extra_manifest_lines = []): + extra_manifest_lines = [], + exclude_build_data = False): """ Registers actions for _deploy.jar and _deploy.jar.unstripped Args: @@ -49,6 +50,7 @@ def create_deploy_archives( one_version_allowlist: (File) Optional allowlist for one version check extra_args: (list[Args]) Optional arguments for the deploy jar action extra_manifest_lines: (list[String]) Optional lines added to the jar manifest + exclude_build_data: (bool) Whether to omit build-data.properties """ classpath_resources = java_attrs.classpath_resources @@ -61,7 +63,10 @@ def create_deploy_archives( order = "preorder", ) multi_release = ctx.fragments.java.multi_release_deploy_jars - build_info_files = helper.get_build_info(ctx, ctx.attr.stamp) + if exclude_build_data and ctx.attr.stamp == 1: + fail("Enabling stamping has no effect with exclude_build_data enabled") + + build_info_files = [] if exclude_build_data else helper.get_build_info(ctx, ctx.attr.stamp) build_target = str(ctx.label) manifest_lines = ctx.attr.deploy_manifest_lines + extra_manifest_lines create_deploy_archive( @@ -75,6 +80,7 @@ def create_deploy_archives( build_info_files, build_target, output = ctx.outputs.deployjar, + exclude_build_data = exclude_build_data, one_version_level = one_version_level, one_version_allowlist = one_version_allowlist, multi_release = multi_release, @@ -96,6 +102,7 @@ def create_deploy_archives( build_info_files, build_target, output = ctx.outputs.unstrippeddeployjar, + exclude_build_data = exclude_build_data, multi_release = multi_release, hermetic = hermetic, add_exports = add_exports, @@ -122,7 +129,8 @@ def create_deploy_archive( hermetic = False, add_exports = [], add_opens = [], - extra_args = []): + extra_args = [], + exclude_build_data = False): """ Creates a deploy jar Requires a Java runtime toolchain if and only if hermetic is True. @@ -146,6 +154,7 @@ def create_deploy_archive( add_exports: (depset) add_opens: (depset) extra_args: (list[Args]) Optional arguments for the deploy jar action + exclude_build_data: (bool) Whether to omit build-data.properties """ input_files = [] input_files.extend(build_info_files) @@ -172,7 +181,10 @@ def create_deploy_archive( if main_class: args.add("--main_class", main_class) args.add_all("--deploy_manifest_lines", manifest_lines) - args.add_all(build_info_files, before_each = "--build_info_file") + if exclude_build_data: + args.add("--exclude_build_data") + else: + args.add_all(build_info_files, before_each = "--build_info_file") if launcher: input_files.append(launcher) args.add("--java_launcher", launcher) diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 8436e0e6..107f63f9 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -1,9 +1,11 @@ """Tests for the Bazel java_binary rule""" +load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") +load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:rules/template_var_info_rule.bzl", "template_var_info_rule") @@ -49,6 +51,66 @@ def _test_java_binary_cross_compilation_to_unix_impl(env, target): assert_action.substitutions().keys().contains("%jvm_flags%") assert_action.inputs().contains_exactly(["java/bazel/rules/java_stub_template.txt"]) +def _test_java_binary_excludes_build_data(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Main.java"], + exclude_build_data = True, + ) + + analysis_test( + name = name, + impl = _test_java_binary_excludes_build_data_impl, + target = name + "/bin", + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_binary_excludes_build_data_impl(env, target): + assert_deploy_jar_action = env.expect.that_target(target).action_generating( + "{package}/{name}_deploy.jar", + ) + + assert_deploy_jar_action.argv().contains("--normalize") + assert_deploy_jar_action.argv().contains("--exclude_build_data") + assert_deploy_jar_action.argv().not_contains("--build_info_file") + assert_deploy_jar_action.inputs().not_contains_predicate( + matching.file_basename_equals("non_volatile_file.properties"), + ) + assert_deploy_jar_action.inputs().not_contains_predicate( + matching.file_basename_equals("redacted_file.properties"), + ) + +def _test_java_binary_stamping_enabled_build_data_excluded_fails(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Main.java"], + exclude_build_data = True, + stamp = 1, + ) + + analysis_test( + name = name, + impl = _test_java_binary_stamping_enabled_build_data_excluded_fails_impl, + target = name + "/bin", + expect_failure = True, + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_java_binary_stamping_enabled_build_data_excluded_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("Enabling stamping has no effect with exclude_build_data enabled"), + ) + def _test_java_binary_javacopts_make_variable_expansion(name): util.helper_target( template_var_info_rule, @@ -137,6 +199,8 @@ def java_binary_tests(name): name = name, tests = [ _test_java_binary_cross_compilation_to_unix, + _test_java_binary_excludes_build_data, + _test_java_binary_stamping_enabled_build_data_excluded_fails, _test_java_binary_javacopts_make_variable_expansion, _test_java_binary_javacopts_location_expansion, _test_java_binary_resource_strip_prefix, diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 496a0053..b8add399 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -56,6 +56,9 @@ def _test_stamp_conversion_does_not_override_int_impl(env, target): "{package}/{name}_deploy.jar", ) + assert_deploy_jar_action.argv().contains("--normalize") + assert_deploy_jar_action.argv().not_contains("--exclude_build_data") + assert_deploy_jar_action.argv().contains("--build_info_file") assert_deploy_jar_action.inputs().not_contains_predicate( matching.file_basename_equals("non_volatile_file.properties"), ) From 3b9d0f2f1986d1bdbdd01b04c069cbeb8e1ac5ef Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 26 Aug 2026 03:21:50 -0700 Subject: [PATCH 219/251] Internal change[^1] PiperOrigin-RevId: 971160491 Change-Id: Icc786bd1b96e58e57c48e488c07c9ceac3030abd --- test/java/testutil/javac_action_subject.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index 794f35a7..41bf2e35 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -44,6 +44,7 @@ def _new_javac_action_subject(env, target, output = None, desc = ""): argv = action_subject.argv, mnemonic = action_subject.mnemonic, native_header_output = lambda: _create_subject_for_flag("--native_header_output", self.parsed_flags, self.meta), + fix_deps_tool = lambda: _create_subject_for_flag("--experimental_fix_deps_tool", self.parsed_flags, self.meta).offset(0, factory = subjects.str), ) return public From 54439b996b26e7ed2d6c0cb907835515c7f40618 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 26 Aug 2026 10:31:59 -0700 Subject: [PATCH 220/251] Fix `java_single_jar` to propagate full transitive classpath and use shell param file format `java_single_jar` previously set `runtime_classpath = inputs` in `JavaRuntimeClasspathInfo`, which only included the filtered outputs rather than the full transitive runtime dependencies (`all_inputs`). When `java_single_jar` targets were used in `deploy_env` of other deploy JAR rules, dependencies excluded from the inner JAR were not properly excluded from the outer JAR. Also configure `args.set_param_file_format("shell")` (matching `java_binary_deploy_jar.bzl`) so arguments in `deploy_manifest_lines` containing whitespace or embedded newlines are properly quoted in param files. Add unit tests for `deploy_manifest_lines`, transitive `deploy_env` exclusion, and `java_binary` consuming `java_single_jar` via `deploy_env`. PiperOrigin-RevId: 971365057 Change-Id: I47df6dbe444d1e5d29fabc730ee4d68555332a25 --- java/common/rules/java_single_jar.bzl | 11 +- .../common/rules/java_single_jar_tests.bzl | 118 ++++++++++++++++++ 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl index ca768873..54e9f285 100644 --- a/java/common/rules/java_single_jar.bzl +++ b/java/common/rules/java_single_jar.bzl @@ -37,7 +37,8 @@ def _single_jar_inputs(deps, deploy_env): fail("unexpected file type in java_single_jar.deps: %s" % f.path) files.append(f) transitive_inputs.append(depset(files)) - inputs = depset(transitive = transitive_inputs) + all_inputs = depset(transitive = transitive_inputs) + inputs = all_inputs if hasattr(java_common, "JavaRuntimeClasspathInfo"): deploy_env_jars = depset(transitive = [ @@ -47,15 +48,15 @@ def _single_jar_inputs(deps, deploy_env): excluded_jars = {jar: None for jar in deploy_env_jars.to_list()} if excluded_jars: inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars]) - return inputs + return inputs, all_inputs def _bazel_java_single_jar_impl(ctx): - inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) + inputs, all_inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) args = ctx.actions.args() args.add_all("--sources", inputs) args.use_param_file("@%s") - args.set_param_file_format("multiline") + args.set_param_file_format("shell") args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines) args.add("--output", ctx.outputs.output) args.add("--normalize") @@ -102,7 +103,7 @@ def _bazel_java_single_jar_impl(ctx): runfiles = ctx.runfiles(transitive_files = files), )] if hasattr(java_common, "JavaRuntimeClasspathInfo"): - providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs)) + providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = all_inputs)) return providers bazel_java_single_jar = rule( diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index 488aab3f..7d0796af 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -3,6 +3,8 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") load("//java:java_single_jar.bzl", "java_single_jar") load("//java/common:java_semantics.bzl", "semantics") @@ -155,15 +157,131 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets) for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() ]) +def _test_java_single_jar_deploy_manifest_lines(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + deps = ["1.jar"], + deploy_manifest_lines = [ + "Manifest-Entry-A: valueA", + "Manifest-Entry-B: line1,\n line2", + ], + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_deploy_manifest_lines_impl, + target = name + "/jar", + ) + +def _test_java_single_jar_deploy_manifest_lines_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.argv().contains_at_least([ + "--deploy_manifest_lines", + "Manifest-Entry-A: valueA", + "Manifest-Entry-B: line1,\n line2", + ]) + +def _test_java_single_jar_transitive_deploy_env(name): + util.helper_target( + java_library, + name = name + "_lib_a", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_b", + srcs = ["B.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_c", + srcs = ["C.java"], + ) + util.helper_target( + java_single_jar, + name = name + "_env1", + deps = [name + "_lib_a"], + ) + util.helper_target( + java_single_jar, + name = name + "_inner", + deps = [name + "_lib_a", name + "_lib_b"], + deploy_env = [name + "_env1"], + ) + util.helper_target( + java_single_jar, + name = name + "_outer", + deps = [name + "_lib_a", name + "_lib_b", name + "_lib_c"], + deploy_env = [name + "_inner"], + ) + + analysis_test( + name = name, + impl = _test_java_single_jar_transitive_deploy_env_impl, + target = name + "_outer", + ) + +def _test_java_single_jar_transitive_deploy_env_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.argv().contains_at_least([ + "--sources", + "{bindir}/{package}/lib{test_name}_lib_c.jar", + "--output", + ]) + assert_that_action.argv().not_contains("{bindir}/{package}/lib{test_name}_lib_a.jar") + assert_that_action.argv().not_contains("{bindir}/{package}/lib{test_name}_lib_b.jar") + +def _test_java_binary_deploy_env_with_java_single_jar(name): + util.helper_target( + java_library, + name = name + "_lib_a", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_b", + srcs = ["B.java"], + ) + util.helper_target( + java_single_jar, + name = name + "_single_jar", + deps = [name + "_lib_a"], + ) + util.helper_target( + java_binary, + name = name + "_bin", + main_class = "Main", + runtime_deps = [name + "_lib_a", name + "_lib_b"], + deploy_env = [name + "_single_jar"], + ) + + analysis_test( + name = name, + attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 + impl = _test_java_binary_deploy_env_with_java_single_jar_impl, + target = name + "_bin", + ) + +def _test_java_binary_deploy_env_with_java_single_jar_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaDeployJar") + assert_that_action.inputs().contains_at_least([ + "{package}/lib{test_name}_lib_b.jar", + ]) + assert_that_action.inputs().not_contains("{package}/lib{test_name}_lib_a.jar") + def java_single_jar_tests(name): test_suite( name = name, tests = [ _test_java_single_jar_basic, + _test_java_single_jar_deploy_manifest_lines, _test_java_single_jar_force_enable_stamping, _test_java_single_jar_force_disable_stamping, _test_java_single_jar_stamping_enabled_build_data_excluded_fails, _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled, _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled, + _test_java_single_jar_transitive_deploy_env, + _test_java_binary_deploy_env_with_java_single_jar, ], ) From 14ed0f17331aae0d9622785499d3aebaf45b2301 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 28 Aug 2026 01:43:03 -0700 Subject: [PATCH 221/251] Fix `@rules_java` CI after https://github.com/bazelbuild/bazel/commit/3b812d349882f0a12028f16379b83de757796737 Replace the now forbidden `/` with `_` as the separator in `platform` target names. (ignore-relnotes) PiperOrigin-RevId: 972431951 Change-Id: Id97e6ad920da8751a3f7cedcc1d691abf4a94999 --- test/java/bazel/rules/java_binary_tests.bzl | 4 ++-- test/java/common/rules/java_test_tests.bzl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 107f63f9..a36a9116 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -16,7 +16,7 @@ def _test_java_binary_cross_compilation_to_unix(name): # - is not supported by the default C++ toolchain util.helper_target( native.platform, - name = name + "/platform", + name = name + "_platform", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:s390x", @@ -35,7 +35,7 @@ def _test_java_binary_cross_compilation_to_unix(name): impl = _test_java_binary_cross_compilation_to_unix_impl, target = name + "/bin", config_settings = { - "//command_line_option:platforms": [Label(name + "/platform")], + "//command_line_option:platforms": [Label(name + "_platform")], }, # Requires the launcher_maker toolchain. attr_values = {"tags": ["min_bazel_9"]}, diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 1468fcc8..4109d2ad 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -212,7 +212,7 @@ def _test_stamp_values_impl(env, targets): def _test_mac_requires_darwin_for_execution(name): util.helper_target( rule = native.platform, - name = name + "/darwin_x86_64", + name = name + "_darwin_x86_64", constraint_values = [ "@platforms//os:macos", "@platforms//cpu:x86_64", @@ -244,7 +244,7 @@ def _test_mac_requires_darwin_for_execution(name): name = name, target = name + "/test", config_settings = { - "//command_line_option:platforms": [Label(name + "/darwin_x86_64")], + "//command_line_option:platforms": [Label(name + "_darwin_x86_64")], "//command_line_option:extra_toolchains": toolchains, }, impl = _test_mac_requires_darwin_for_execution_impl, From 1beac495c21d853805d24743d8be1ce88249c222 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 31 Aug 2026 02:36:09 -0700 Subject: [PATCH 222/251] Add a test for `java_binary` deps without srcs (ignore-relnotes) PiperOrigin-RevId: 973761700 Change-Id: Ibeda103175adfa41859052e7755fb6806accfc58 --- test/java/common/rules/java_binary_tests.bzl | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index b8add399..20c6ee07 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -512,6 +512,32 @@ def _test_java_binary_jdeps_impl(env, target): ("--output_deps_proto", "{bindir}/{package}/{name}.jdeps"), ]) +def _test_java_binary_deps_without_srcs(name): + util.helper_target( + java_binary, + name = name + "/a", + srcs = [], + deps = [name + "/b"], + main_class = "B", + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_deps_without_srcs_impl, + target = name + "/a", + expect_failure = True, + ) + +def _test_java_binary_deps_without_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("deps not allowed without srcs"), + ) + def java_binary_tests(name): test_suite( name = name, @@ -530,5 +556,6 @@ def java_binary_tests(name): _test_java_binary_rule_in_sub_directory, _test_java_binary_duplicate_classpath_resources, _test_java_binary_jdeps, + _test_java_binary_deps_without_srcs, ], ) From 0a9737fe91827fe8ed0f9e55bbf903597fd3eb0d Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 1 Sep 2026 02:01:22 -0700 Subject: [PATCH 223/251] Propagate `.jdeps` for `java_import` (#363) Downstream Java compilation actions need accurate `.jdeps` files for their reduced classpath optimization. With this change, `java_import` now always runs `ImportDepsChecker` to generate this file, but possibly suppresses its outputs. Note that Bazel (but not Blaze) always silences the output. Fixes #362 Closes #363 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/363 from fmeum:java-import-reduced-classpath 5daac7d7ba1eeb7016d5a2921bdd58d93722c586 PiperOrigin-RevId: 974359803 Change-Id: I151170f6382202f8faae0c75c52741920d45c81e --- .../rules/impl/bazel_java_import_impl.bzl | 28 +++++++---- java/common/rules/impl/import_deps_check.bzl | 10 ++-- test/java/bazel/rules/BUILD.bazel | 3 ++ test/java/bazel/rules/java_import_tests.bzl | 42 +++++++++++++++++ test/java/common/rules/java_import_tests.bzl | 46 +++++++++++++++++++ test/java/testutil/java_info_subject.bzl | 3 +- toolchains/default_java_toolchain.bzl | 1 + 7 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 test/java/bazel/rules/java_import_tests.bzl diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index c402fc44..aa829d1f 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl @@ -115,16 +115,23 @@ def bazel_java_import_rule( collected_jars = _collect_jars(ctx, jars) all_deps = _filter_provider(JavaInfo, deps, exports) - jdeps_artifact = None merged_java_info = java_common.merge(all_deps) - if not skip_incomplete_deps_check and "incomplete-deps" not in ctx.attr.tags: - jdeps_artifact = import_deps_check( - ctx, - collected_jars, - merged_java_info.compile_jars, - merged_java_info.transitive_compile_time_jars, - "java_import", - ) + + # import_deps_check is always run to generate the jdeps proto for downstream compile actions, + # but may be silenced. + has_incomplete_deps = "incomplete-deps" in ctx.attr.tags + if skip_incomplete_deps_check or has_incomplete_deps: + checking_mode = "silence" + else: + checking_mode = "error" + jdeps_artifact = import_deps_check( + ctx, + collected_jars, + merged_java_info.compile_jars, + merged_java_info.transitive_compile_time_jars, + "java_import", + checking_mode = checking_mode, + ) compilation_to_runtime_jar_map = _process_with_ijars_if_needed(collected_jars, ctx) runtime_deps_list = [runtime_dep[JavaInfo] for runtime_dep in runtime_deps if JavaInfo in runtime_dep] @@ -134,6 +141,7 @@ def bazel_java_import_rule( java_infos.append(JavaInfo( output_jar = jar, compile_jar = compilation_to_runtime_jar_map[jar], + compile_jdeps = jdeps_artifact, deps = all_deps, runtime_deps = runtime_deps_list, neverlink = neverlink, @@ -169,7 +177,7 @@ def bazel_java_import_rule( output_group_src_jars = depset() if srcjar == None else depset([srcjar]) validation_group = [] - if jdeps_artifact != None: + if jdeps_artifact != None and checking_mode != "silence": validation_group.append(jdeps_artifact) if srcjar != None: validation_group.append(srcjar) diff --git a/java/common/rules/impl/import_deps_check.bzl b/java/common/rules/impl/import_deps_check.bzl index 69dec8b6..f5a950f7 100644 --- a/java/common/rules/impl/import_deps_check.bzl +++ b/java/common/rules/impl/import_deps_check.bzl @@ -23,7 +23,8 @@ def import_deps_check( jars_to_check, declared_deps, transitive_deps, - rule_class): + rule_class, + checking_mode = "error"): """ Creates actions that checks import deps for java rules. @@ -33,6 +34,7 @@ def import_deps_check( declared_deps: (list[File]) A list of direct dependencies. transitive_deps: (list[File]) A list of transitive dependencies. rule_class: (String) Rule class. + checking_mode: (String) One of "error", "warning" or "silence". Returns: (File) Output file of the created action. @@ -53,9 +55,11 @@ def import_deps_check( before_each = "--classpath_entry", ) args.add_all(java_toolchain.bootclasspath, before_each = "--bootclasspath_entry") - args.add("--checking_mode=error") + args.add(checking_mode, format = "--checking_mode=%s") args.add("--jdeps_output", jdeps_output) - args.add("--rule_label", ctx.label) + + # ctx.label can start with an @ and must not be understood as a flagfile. + args.add(ctx.label, format = "--rule_label=%s") semantics.update_args_for_import_deps(ctx, args) inputs = depset( diff --git a/test/java/bazel/rules/BUILD.bazel b/test/java/bazel/rules/BUILD.bazel index 6f97d15a..09c1f1a0 100644 --- a/test/java/bazel/rules/BUILD.bazel +++ b/test/java/bazel/rules/BUILD.bazel @@ -1,10 +1,13 @@ load(":java_binary_tests.bzl", "java_binary_tests") +load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") load(":java_test_tests.bzl", "java_test_tests") java_binary_tests(name = "java_binary_tests") +java_import_tests(name = "java_import_tests") + java_library_tests(name = "java_library_tests") java_plugin_tests(name = "java_plugin_tests") diff --git a/test/java/bazel/rules/java_import_tests.bzl b/test/java/bazel/rules/java_import_tests.bzl new file mode 100644 index 00000000..8ea3ff2e --- /dev/null +++ b/test/java/bazel/rules/java_import_tests.bzl @@ -0,0 +1,42 @@ +"""Tests for the Bazel java_import rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_import.bzl", "java_import") + +def _test_import_deps_checker_checking_mode(name): + util.helper_target( + java_import, + name = name + "/import-jar", + jars = ["import.jar"], + deps = [name + "/depjar"], + ) + util.helper_target( + java_import, + name = name + "/depjar", + jars = ["depjar.jar"], + ) + + analysis_test( + name = name, + impl = _test_import_deps_checker_checking_mode_impl, + target = name + "/import-jar", + # The rules_java Starlark implementation is used from Bazel 8 on. + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_import_deps_checker_checking_mode_impl(env, target): + # java_import only generates the jdeps proto, it never fails the build on incomplete deps. + assert_action = env.expect.that_target(target).action_named("ImportDepsChecker") + assert_action.contains_flag_values([ + ("--checking_mode", "silence"), + ("--rule_label", "//{package}:{name}"), + ]) + +def java_import_tests(name): + test_suite( + name = name, + tests = [ + _test_import_deps_checker_checking_mode, + ], + ) diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl index 35b713df..c74bd3de 100644 --- a/test/java/common/rules/java_import_tests.bzl +++ b/test/java/common/rules/java_import_tests.bzl @@ -178,6 +178,51 @@ def _test_deps_impl(env, targets): "{package}/depjar.jar", ]) +# Regression test for https://github.com/bazelbuild/rules_java/issues/362: every java_import +# records a jdeps proto as its compile_jdeps so that reduced classpaths of downstream compilations +# are not missing its transitive dependencies. +def _test_compile_jdeps_propagated_for_deps(name): + util.helper_target( + java_import, + name = name + "/import-jar", + jars = ["import.jar"], + deps = [name + "/depjar"], + ) + util.helper_target( + java_import, + name = name + "/incomplete-jar", + jars = ["incomplete.jar"], + deps = [name + "/depjar"], + tags = ["incomplete-deps"], + ) + util.helper_target( + java_import, + name = name + "/depjar", + jars = ["depjar.jar"], + ) + + analysis_test( + name = name, + impl = _test_compile_jdeps_propagated_for_deps_impl, + targets = { + "incomplete_deps": name + "/incomplete-jar", + "with_deps": name + "/import-jar", + "without_deps": name + "/depjar", + }, + # The rules_java Starlark implementation is used from Bazel 8 on. + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_compile_jdeps_propagated_for_deps_impl(env, targets): + for name in ["with_deps", "without_deps", "incomplete_deps"]: + java_info_subject.from_target( + env, + getattr(targets, name), + expr = name, + ).compilation_args().compile_time_java_dependencies().contains_exactly([ + "{package}/_java_import/{name}/jdeps.proto", + ]) + # Regression test for b/262751943. def _test_commandline_contains_target_label(name): util.helper_target( @@ -959,6 +1004,7 @@ def java_import_tests(name): _test_simple, _test_with_java_library, _test_deps, + _test_compile_jdeps_propagated_for_deps, _test_commandline_contains_target_label, _test_java_library_allows_import_in_deps, _test_module_flags, diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index 9a0fb533..8df4f786 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -31,8 +31,9 @@ def _new_java_info_subject(java_info, meta): ) return public -def _java_info_subject_from_target(env, target): +def _java_info_subject_from_target(env, target, expr = None): return _new_java_info_subject(target[JavaInfo], meta = truth.expect(env).meta.derive( + expr = expr, format_str_kwargs = { "name": target.label.name, "package": target.label.package, diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index e4097ae0..f131a620 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -76,6 +76,7 @@ _DEFAULT_JAVA_LANGUAGE_VERSION = "11" # Default java_toolchain parameters _BASE_TOOLCHAIN_CONFIGURATION = dict( + deps_checker = Label("@remote_java_tools//:ImportDepsChecker"), forcibly_disable_header_compilation = False, genclass = Label("@remote_java_tools//:GenClass"), header_compiler = Label("@remote_java_tools//:TurbineDirect"), From 4c46605384381b2e34c2b5790a3c44b4c9685faf Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 1 Sep 2026 03:10:04 -0700 Subject: [PATCH 224/251] Add a test for `java_binary` srcs file types (ignore-relnotes) PiperOrigin-RevId: 974388917 Change-Id: I6288c87f9691f95b9aa4b95db174d9a0f338dd5c --- test/java/common/rules/a.foo | 0 test/java/common/rules/java_binary_tests.bzl | 67 ++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/java/common/rules/a.foo diff --git a/test/java/common/rules/a.foo b/test/java/common/rules/a.foo new file mode 100644 index 00000000..e69de29b diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 20c6ee07..8b688e11 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -538,6 +538,72 @@ def _test_java_binary_deps_without_srcs_impl(env, target): matching.str_matches("deps not allowed without srcs"), ) +def _test_java_binary_srcs_filetypes(name): + util.helper_target( + java_binary, + name = name + "/valid", + srcs = [ + "a.java", + name + "/gmix", + name + "/gvalid", + ], + ) + util.helper_target( + java_binary, + name = name + "/invalid", + srcs = [ + "a.foo", + name + "/ginvalid", + ], + ) + util.helper_target( + java_binary, + name = name + "/mix", + srcs = [ + "a.foo", + "a.java", + ], + ) + util.helper_target( + native.genrule, + name = name + "/gvalid", + outs = [name + "/b.java"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/ginvalid", + outs = [name + "/b.foo"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/gmix", + outs = [name + "/c.java", name + "/c.foo"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_binary_srcs_filetypes_impl, + targets = { + "valid": name + "/valid", + "invalid": name + "/invalid", + "mix": name + "/mix", + }, + expect_failure = True, + ) + +def _test_java_binary_srcs_filetypes_impl(env, targets): + env.expect.that_target(targets.valid).failures().contains_exactly([]) + env.expect.that_target(targets.invalid).failures().contains_at_least_predicates([ + matching.str_matches("'*/ginvalid' does not produce any java_binary srcs files"), + matching.str_matches("source file '*:a.foo' is misplaced here"), + ]) + env.expect.that_target(targets.mix).failures().contains_at_least_predicates([ + matching.str_matches("'*:a.foo' does not produce any java_binary srcs files"), + ]) + def java_binary_tests(name): test_suite( name = name, @@ -557,5 +623,6 @@ def java_binary_tests(name): _test_java_binary_duplicate_classpath_resources, _test_java_binary_jdeps, _test_java_binary_deps_without_srcs, + _test_java_binary_srcs_filetypes, ], ) From d79223bffcd5307d020311381f46f892e0878911 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 2 Sep 2026 02:00:56 -0700 Subject: [PATCH 225/251] Add a test for `java_test` srcs file types (ignore-relnotes) PiperOrigin-RevId: 974989653 Change-Id: I8572bcca311c1fdf91f7361dd6c3f20bdce0d027 --- test/java/common/rules/java_test_tests.bzl | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 4109d2ad..04674ee7 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -396,6 +396,72 @@ def _test_one_version_check_disabled_for_java_test_impl(env, targets): env.expect.that_collection(binary_action_mnemonics).contains("JavaOneVersion") env.expect.that_collection(test_action_mnemonics).not_contains("JavaOneVersion") +def _test_java_test_srcs_filetypes(name): + util.helper_target( + java_test, + name = name + "/valid", + srcs = [ + "a.java", + name + "/gmix", + name + "/gvalid", + ], + ) + util.helper_target( + java_test, + name = name + "/invalid", + srcs = [ + "a.foo", + name + "/ginvalid", + ], + ) + util.helper_target( + java_test, + name = name + "/mix", + srcs = [ + "a.foo", + "a.java", + ], + ) + util.helper_target( + native.genrule, + name = name + "/gvalid", + outs = [name + "/b.java"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/ginvalid", + outs = [name + "/b.foo"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/gmix", + outs = [name + "/c.java", name + "/c.foo"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_test_srcs_filetypes_impl, + targets = { + "valid": name + "/valid", + "invalid": name + "/invalid", + "mix": name + "/mix", + }, + expect_failure = True, + ) + +def _test_java_test_srcs_filetypes_impl(env, targets): + env.expect.that_target(targets.valid).failures().contains_exactly([]) + env.expect.that_target(targets.invalid).failures().contains_at_least_predicates([ + matching.str_matches("'*/ginvalid' does not produce any java_test srcs files"), + matching.str_matches("source file '*:a.foo' is misplaced here"), + ]) + env.expect.that_target(targets.mix).failures().contains_at_least_predicates([ + matching.str_matches("'*:a.foo' does not produce any java_test srcs files"), + ]) + def java_test_tests(name): test_suite( name = name, @@ -409,5 +475,6 @@ def java_test_tests(name): _test_java_test_sets_securiry_manager_property_jdk17, _test_one_version_check_java_test, _test_one_version_check_disabled_for_java_test, + _test_java_test_srcs_filetypes, ], ) From 7422b05c89f5ab06e2e19feeb02b901bc31dc389 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 2 Sep 2026 09:14:11 -0700 Subject: [PATCH 226/251] Enable path mapping for JavaDeployJar Enable execution_requirements = {"supports-path-mapping": "1"} on the JavaDeployJar action registration in rules_java across all deploy JARs. Map each hermetic resource to its configuration-independent `short_path` using SingleJar's `:` syntax and set `--hermetic_java_home` to `runtime.java_home_runfiles_path`. This allows path mapping to be safely enabled unconditionally across both hermetic and non-hermetic deploy JARs. PiperOrigin-RevId: 975165217 Change-Id: I9f8544e9bc26ace4378898af6152ccbf526aaaa1 --- java/common/rules/impl/java_binary_deploy_jar.bzl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index b315bc35..41cc9bf6 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -19,6 +19,9 @@ load(":java_helper.bzl", "helper") # copybara: default visibility +def _map_hermetic_resource(f): + return "%s:%s" % (f.path, f.short_path) + def create_deploy_archives( ctx, java_attrs, @@ -208,13 +211,17 @@ def create_deploy_archive( if hermetic: runtime = ctx.toolchains["@//tools/jdk/hermetic:hermetic_runtime_toolchain_type"].java_runtime if runtime.lib_modules != None: - java_home = runtime.java_home + java_home = runtime.java_home_runfiles_path lib_modules = runtime.lib_modules hermetic_files = runtime.hermetic_files default_cds = runtime.default_cds args.add("--hermetic_java_home", java_home) args.add("--jdk_lib_modules", lib_modules) - args.add_all("--resources", hermetic_files) + args.add_all( + "--resources", + hermetic_files, + map_each = _map_hermetic_resource, + ) input_files.append(lib_modules) transitive_input_files.append(hermetic_files) if default_cds: @@ -234,6 +241,9 @@ def create_deploy_archive( tools = [single_jar], outputs = [output], arguments = [args] + extra_args, + execution_requirements = { + "supports-path-mapping": "1", + }, use_default_shell_env = True, toolchain = semantics.JAVA_TOOLCHAIN_TYPE, ) From f2a3c63a4aae12dc11bd899128d4192aaba9e46c Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 4 Sep 2026 04:23:15 -0700 Subject: [PATCH 227/251] Prepare `java_single_jar_tests.bzl` for enabling path stripping (ignore-relnotes) PiperOrigin-RevId: 976240384 Change-Id: I712ec32ffab340f035e275e64406c2fceab5603f --- MODULE.bazel | 6 +- .../common/rules/java_single_jar_tests.bzl | 139 +++++++++++++----- 2 files changed, 103 insertions(+), 42 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index a088efe7..6135ff78 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -124,9 +124,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-ZmrwZSmn3NkEj0MOnix9oSMzPXJWbuJbCCbOM1C03QQ=", - strip_prefix = "rules_testing-ff65fc8b7f1b7c37de71d781601ff40288de80f2", - urls = ["https://github.com/bazelbuild/rules_testing/archive/ff65fc8b7f1b7c37de71d781601ff40288de80f2.tar.gz"], + integrity = "sha256-UlGXv0mAHt6sQtadxJ97TeqrJVIaKP7X+M8SrNpqM7s=", + strip_prefix = "rules_testing-2529012de853e1147460363c04dbe911c1025a6b", + urls = ["https://github.com/bazelbuild/rules_testing/archive/2529012de853e1147460363c04dbe911c1025a6b.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index 7d0796af..bc085206 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -1,13 +1,61 @@ """Tests for the java_single_jar rule""" -load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_testing//lib:analysis_test.bzl", _analysis_test = "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") +load("@rules_testing//lib/private:util.bzl", "get_test_name_from_function") # buildifier: disable=bzl-visibility load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_single_jar.bzl", "java_single_jar") load("//java/common:java_semantics.bzl", "semantics") +def _path_stripping_analysis_test(name, impl, config_settings = {}, **kwargs): + if name.endswith("_off"): + output_path_mode = "off" + elif name.endswith("_strip"): + output_path_mode = "strip" + else: + fail("expected test name to end with one of [_strip, _off]") + + # TODO: remove once Bazel 7 is no longer supported + if bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + config_settings = config_settings | { + "//command_line_option:experimental_output_paths": output_path_mode, + } + + _analysis_test( + name = name, + impl = lambda env, target: impl(env, target, output_path_mode), + config_settings = config_settings, + **kwargs + ) + +def _path_stripping_test_suite(name, *, tests = [], test_kwargs = {}): + """Expands each test into 'off' and 'strip' output path mode variants""" + test_targets = [] + for suffix in ["_off", "_strip"]: + for setup_func in tests: + test_name = get_test_name_from_function(setup_func) + suffix + setup_func(name = test_name, **test_kwargs) + test_targets.append(test_name) + native.test_suite( + name = name, + tests = test_targets, + ) + +def _get_bindir_for_output_path_mode(output_path_mode): + # TODO: remove once Bazel 7 is no longer supported + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + return "{bindir}" + + if output_path_mode == "off": + return "{bindir}" + elif output_path_mode == "strip": + # TODO(b/554023226): use "{cfg_stripped_bindir}" once java_single_jar opts into path stripping + return "{bindir}" + fail("unexpected output path mode: " + output_path_mode) + def _test_java_single_jar_basic(name): util.helper_target( java_single_jar, @@ -15,20 +63,20 @@ def _test_java_single_jar_basic(name): deps = ["1.jar", "2.jar"], ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_basic_impl, target = name + "/jar", ) -def _test_java_single_jar_basic_impl(env, target): +def _test_java_single_jar_basic_impl(env, target, output_path_mode): assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") assert_that_action.argv().contains_at_least([ "--sources", "{package}/1.jar", "{package}/2.jar", "--output", - "{bindir}/{package}/{name}.jar", + _get_bindir_for_output_path_mode(output_path_mode) + "/{package}/{name}.jar", "--normalize", "--dont_change_compression", "--exclude_build_data", @@ -43,7 +91,7 @@ def _test_java_single_jar_force_enable_stamping(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_force_enable_stamping_impl, targets = { @@ -52,13 +100,22 @@ def _test_java_single_jar_force_enable_stamping(name): }, ) -def _test_java_single_jar_force_enable_stamping_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") +def _assert_build_info_files(env, jar_target, build_info_files, output_path_mode): + bin_dir = _get_bindir_for_output_path_mode(output_path_mode) + assert_that_action = env.expect.that_target(jar_target).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() + ("--build_info_file", bin_dir + f.path[len(f.root.path):]) + for f in build_info_files.to_list() ]) +def _test_java_single_jar_force_enable_stamping_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].non_redacted_build_info_files, + output_path_mode, + ) + def _test_java_single_jar_force_disable_stamping(name): util.helper_target( java_single_jar, @@ -67,7 +124,7 @@ def _test_java_single_jar_force_disable_stamping(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_force_disable_stamping_impl, targets = { @@ -76,12 +133,13 @@ def _test_java_single_jar_force_disable_stamping(name): }, ) -def _test_java_single_jar_force_disable_stamping_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() - ]) +def _test_java_single_jar_force_disable_stamping_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].redacted_build_info_files, + output_path_mode, + ) def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): util.helper_target( @@ -91,7 +149,7 @@ def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): exclude_build_data = True, ) - analysis_test( + _analysis_test( name = name, impl = _test_java_single_jar_stamping_enabled_build_data_excluded_fails_impl, target = name + "/jar", @@ -111,7 +169,7 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl, targets = { @@ -123,12 +181,13 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() - ]) +def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].non_redacted_build_info_files, + output_path_mode, + ) def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): util.helper_target( @@ -138,7 +197,7 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl, targets = { @@ -150,12 +209,13 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() - ]) +def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].redacted_build_info_files, + output_path_mode, + ) def _test_java_single_jar_deploy_manifest_lines(name): util.helper_target( @@ -168,7 +228,7 @@ def _test_java_single_jar_deploy_manifest_lines(name): ], ) - analysis_test( + _analysis_test( name = name, impl = _test_java_single_jar_deploy_manifest_lines_impl, target = name + "/jar", @@ -216,21 +276,22 @@ def _test_java_single_jar_transitive_deploy_env(name): deploy_env = [name + "_inner"], ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_transitive_deploy_env_impl, target = name + "_outer", ) -def _test_java_single_jar_transitive_deploy_env_impl(env, target): +def _test_java_single_jar_transitive_deploy_env_impl(env, target, output_path_mode): + bin_dir = _get_bindir_for_output_path_mode(output_path_mode) assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") assert_that_action.argv().contains_at_least([ "--sources", - "{bindir}/{package}/lib{test_name}_lib_c.jar", + bin_dir + "/{package}/lib{test_name}_lib_c.jar", "--output", ]) - assert_that_action.argv().not_contains("{bindir}/{package}/lib{test_name}_lib_a.jar") - assert_that_action.argv().not_contains("{bindir}/{package}/lib{test_name}_lib_b.jar") + assert_that_action.argv().not_contains(bin_dir + "/{package}/lib{test_name}_lib_a.jar") + assert_that_action.argv().not_contains(bin_dir + "/{package}/lib{test_name}_lib_b.jar") def _test_java_binary_deploy_env_with_java_single_jar(name): util.helper_target( @@ -256,7 +317,7 @@ def _test_java_binary_deploy_env_with_java_single_jar(name): deploy_env = [name + "_single_jar"], ) - analysis_test( + _analysis_test( name = name, attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 impl = _test_java_binary_deploy_env_with_java_single_jar_impl, @@ -271,7 +332,7 @@ def _test_java_binary_deploy_env_with_java_single_jar_impl(env, target): assert_that_action.inputs().not_contains("{package}/lib{test_name}_lib_a.jar") def java_single_jar_tests(name): - test_suite( + _path_stripping_test_suite( name = name, tests = [ _test_java_single_jar_basic, From 4206909b6d3b1503b3fc51da41d0d529b92d4221 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 5 Sep 2026 00:20:26 -0700 Subject: [PATCH 228/251] Enable path mapping for `java_single_jar`. PiperOrigin-RevId: 976671582 Change-Id: Iea495cd4e2302010aaf0b5943c05b3ab527792f9 --- java/common/rules/java_single_jar.bzl | 3 +++ test/java/common/rules/java_single_jar_tests.bzl | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl index 54e9f285..e36c1b70 100644 --- a/java/common/rules/java_single_jar.bzl +++ b/java/common/rules/java_single_jar.bzl @@ -94,6 +94,9 @@ def _bazel_java_single_jar_impl(ctx): progress_message = "Merging into %s" % ctx.outputs.output.short_path, mnemonic = "JavaSingleJar", executable = ctx.executable._singlejar, + execution_requirements = { + "supports-path-mapping": "1", + }, use_default_shell_env = True, ) diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index bc085206..c2237e73 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -52,8 +52,7 @@ def _get_bindir_for_output_path_mode(output_path_mode): if output_path_mode == "off": return "{bindir}" elif output_path_mode == "strip": - # TODO(b/554023226): use "{cfg_stripped_bindir}" once java_single_jar opts into path stripping - return "{bindir}" + return "{cfg_stripped_bindir}" fail("unexpected output path mode: " + output_path_mode) def _test_java_single_jar_basic(name): From 6a5a89d2f530474e58ec19214d756ec633770f9a Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 9 Sep 2026 01:24:27 -0700 Subject: [PATCH 229/251] Automatic code cleanup. PiperOrigin-RevId: 978385248 Change-Id: If269a56aa93a60e4600a2f70dd45415b5af671bd --- test/java/common/rules/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 97589249..44bb6c3f 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -55,5 +55,5 @@ util.helper_target( "open/one", "open/two", ], - visibility = ["//test/java:__subpackages__"], + visibility = ["//visibility:private"], ) From d11984301010a46228a54d9480d2bf37c05272f1 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 9 Sep 2026 07:35:39 -0700 Subject: [PATCH 230/251] Add a test for `java_binary` runtime_deps transitivity (ignore-relnotes) PiperOrigin-RevId: 978538090 Change-Id: Idd8b5a602bceb84547ed3f80d22a432b0a701061 --- .../common_launcher_java_binary_tests.bzl | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 877f3d45..2fbac4e5 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -4,6 +4,7 @@ load("@bazel_features//:features.bzl", "bazel_features") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") @@ -392,6 +393,86 @@ def _test_java_binary_strict_java_deps_flag_impl(env, targets): "{bindir}/{package}/lib{test_name}/delta-hjar.jar", ]).in_order() +def _test_java_binary_runtime_deps_transitivity(name): + util.helper_target( + java_library, + name = name + "/l0", + srcs = ["l0.java"], + ) + util.helper_target( + java_library, + name = name + "/l1", + srcs = ["l1.java"], + ) + util.helper_target( + java_library, + name = name + "/l2", + srcs = ["l2.java"], + runtime_deps = [name + "/l1"], + deps = [name + "/l0"], + ) + util.helper_target( + java_library, + name = name + "/l3", + srcs = ["l3.java"], + deps = [name + "/l2"], + ) + util.helper_target( + java_library, + name = name + "/l4", + srcs = ["l4.java"], + deps = [name + "/l1"], + ) + util.helper_target( + java_binary, + name = name + "/b1", + srcs = ["b1.java"], + deps = [name + "/l2"], + ) + util.helper_target( + java_binary, + name = name + "/b2", + srcs = ["b2.java"], + runtime_deps = [name + "/l3"], + ) + + analysis_test( + name = name, + attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 + impl = _test_java_binary_runtime_deps_transitivity_impl, + targets = { + "b1": name + "/b1", + "b2": name + "/b2", + }, + ) + +def _expect_that_deploy_jar_action_inputs(env, target, extension): + action = env.expect.that_target(target).action_generating("{package}/{name}_deploy.jar") + return subjects.collection( + action.actual.inputs.to_list(), + meta = action.meta, + ).transform( + desc = extension + " inputs", + filter = lambda f: f.extension == extension, + format = True, + map_each = lambda f: f.short_path, + ) + +def _test_java_binary_runtime_deps_transitivity_impl(env, targets): + _expect_that_deploy_jar_action_inputs(env, targets.b1, "jar").contains_exactly([ + "{package}/lib{test_name}/l0.jar", + "{package}/lib{test_name}/l1.jar", + "{package}/lib{test_name}/l2.jar", + "{package}/{test_name}/b1.jar", + ]) + _expect_that_deploy_jar_action_inputs(env, targets.b2, "jar").contains_exactly([ + "{package}/lib{test_name}/l0.jar", + "{package}/lib{test_name}/l1.jar", + "{package}/lib{test_name}/l2.jar", + "{package}/lib{test_name}/l3.jar", + "{package}/{test_name}/b2.jar", + ]) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -409,5 +490,6 @@ def java_binary_launcher_tests(name): _test_java_binary_inner_class, _test_java_test_inner_class, _test_java_binary_strict_java_deps_flag, + _test_java_binary_runtime_deps_transitivity, ], ) From ca03ec1ccd9347437ca3cfc2749c6a9cd51e1e93 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 10 Sep 2026 09:35:08 -0700 Subject: [PATCH 231/251] Add a test for `java_binary` runtime_deps with transitive data (ignore-relnotes) PiperOrigin-RevId: 979233322 Change-Id: I2b72c1dd3f1ab0af20b7cb25bf90b6aa7b0c4966 --- .../common_launcher_java_binary_tests.bzl | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 2fbac4e5..5096894c 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -473,6 +473,53 @@ def _test_java_binary_runtime_deps_transitivity_impl(env, targets): "{package}/{test_name}/b2.jar", ]) +def _test_java_binary_runtime_deps_with_transitive_data(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Lib.java"], + deps = [name + "/bundle"], + ) + util.helper_target( + java_library, + name = name + "/bundle", + data = [name + "/fava"], + exports = [name + "/bundle2"], + ) + util.helper_target( + java_library, + name = name + "/bundle2", + data = [name + "/extra"], + ) + util.helper_target( + native.filegroup, + name = name + "/fava", + srcs = ["some.js"], + ) + util.helper_target( + native.filegroup, + name = name + "/extra", + srcs = ["some.gss"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_transitive_data_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_transitive_data_impl(env, target): + env.expect.that_target(target).runfiles().contains_at_least([ + "{workspace}/{package}/some.js", + "{workspace}/{package}/some.gss", + ]) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -491,5 +538,6 @@ def java_binary_launcher_tests(name): _test_java_test_inner_class, _test_java_binary_strict_java_deps_flag, _test_java_binary_runtime_deps_transitivity, + _test_java_binary_runtime_deps_with_transitive_data, ], ) From 06558cb3bdffc536f7feb0f979beca37c10be5e5 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 15 Sep 2026 03:57:16 -0700 Subject: [PATCH 232/251] Build `//toolchains/...` again in BazelCI (ignore-relnotes) PiperOrigin-RevId: 981718392 Change-Id: Ia5d26a7ee6d2ce8befbbd41574b3f724e81236da --- .bazelci/presubmit.yml | 2 -- toolchains/BUILD | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 4e826dba..5d3d2f4a 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -8,8 +8,6 @@ build_targets: &build_targets - "@remote_java_tools//:one_version_cc_bin" - "@remote_java_tools//:proguard" - "@remote_java_tools//:singlejar_cc_bin" - # can't build @remote_java_tools_X repos for other platforms - - "-//toolchains/..." build_targets_integration: &build_targets_integration - "//..." diff --git a/toolchains/BUILD b/toolchains/BUILD index 920ae5f1..9d4dd8af 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -302,6 +302,7 @@ alias( "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", }), + tags = ["manual"], # So we can build //... on CI platforms that don't match ) string_setting( From f068a38a8df07469e075182172201c6382aa334c Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 16 Sep 2026 02:48:53 -0700 Subject: [PATCH 233/251] Fix `@rules_java` CI Broken by yesterday's buildifier release: https://github.com/bazel-contrib/buildtools/releases/tag/v10.0.1 (containing https://github.com/bazel-contrib/buildtools/pull/1484) Also update the ubuntu platform as `ubuntu2004` is EOL, see https://github.com/bazelbuild/continuous-integration/pull/2846/changes#diff-a60e9d3d5a335fd36f73da65e8e6a0ad08ef40573831fd96068518b603db6106R339 (ignore-relnotes) PiperOrigin-RevId: 982389191 Change-Id: I97afda62b5ab1f53891bf2d3b5c23efd88c34a5c --- .bazelci/presubmit.yml | 4 ++-- test/BUILD.bazel | 2 +- test/java/toolchains/java_toolchain_tests.bzl | 8 +------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 5d3d2f4a..e9d03fa6 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -26,7 +26,7 @@ flags_workspace_integration: &flags_workspace_integration buildifier: latest matrix: - all_platforms: ["rockylinux8_arm64", "ubuntu2004", "macos", "macos_arm64", "windows"] + all_platforms: ["rockylinux8_arm64", "ubuntu2404", "macos", "macos_arm64", "windows"] bazel: ["7.x", "8.x", "9.x", "last_green"] modern_bazel: ["9.x", "last_green", "rolling"] # Fully supported Bazel versions @@ -85,7 +85,7 @@ tasks: # internal tests for configs and release process internal_tests: name: "Internal tests" - platform: "ubuntu2004" + platform: "ubuntu2404" shell_commands: - "git init" - "git config user.name 'fake-user-for-testing'" diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 9d133ce7..9469fb99 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -54,7 +54,7 @@ sh_test( name = "check_release_notes_test", srcs = ["check_release_notes_test.sh"], args = [ - "$(location //distro:relnotes.txt)", + "$(rootpath //distro:relnotes.txt)", module_version(), ], data = ["//distro:relnotes.txt"], diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 793de8ea..099b5e42 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -296,7 +296,7 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(n analysis_test( name = name, - impl = _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl, + impl = lambda unused_env, unused_target: None, # Implicitly succeeds. target = name + "/a", config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], @@ -304,12 +304,6 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(n }, ) -def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl( - env, # @unused - target): # @unused - # Implicitly succeeds. - pass - def _test_header_compiler_builtin_processors(name): util.helper_target( mock_java_toolchain, From e85d51296d8fc55bfd5fb7413c2e68dbf92b64a8 Mon Sep 17 00:00:00 2001 From: Showta Ishizaki Date: Thu, 17 Sep 2026 05:02:20 -0700 Subject: [PATCH 234/251] Add jni_md_header for NetBSD (#381) The :jni target pulls the machine-dependent jni_md.h out of the JDK per host, with a java_runtime_files target and a select arm for each platform. FreeBSD and OpenBSD are there; add NetBSD, whose JDK ships include/netbsd/jni_md.h just as the others do, so that Bazel's native code builds against the right header when it is bootstrapped there. The config_setting is defined here rather than taken from @bazel_tools//src/conditions, so that it resolves with every Bazel version rather than only those carrying bazelbuild/bazel#31069. @platforms//os:netbsd has been in the platforms module since 0.0.11, which this module already depends on. DragonFly BSD needs @platforms//os:dragonfly, which is not in a platforms release yet (bazelbuild/platforms#143), so it will follow in a separate change. Closes #381 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/381 from zakinko:bsd-jni-headers 0231dcb4b7b00f868f71199d074dd4e3ad198e5f PiperOrigin-RevId: 983122880 Change-Id: I53649e71b4b50134c91d363cedb2eb2436e8d4e0 --- toolchains/BUILD | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/toolchains/BUILD b/toolchains/BUILD index 9d4dd8af..e6056073 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -129,6 +129,19 @@ java_runtime_files( srcs = ["include/openbsd/jni_md.h"], ) +java_runtime_files( + name = "jni_md_header-netbsd", + srcs = ["include/netbsd/jni_md.h"], +) + +# Defined here rather than taken from @bazel_tools//src/conditions so that it +# resolves with every Bazel version: @platforms//os:netbsd has been in the +# platforms module since 0.0.11. +config_setting( + name = "netbsd", + constraint_values = ["@platforms//os:netbsd"], +) + # The Java native interface. Depend on this package if you #include . # # See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for @@ -140,6 +153,7 @@ cc_library( "@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"], "@bazel_tools//src/conditions:linux": [":jni_md_header-linux"], "@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"], + ":netbsd": [":jni_md_header-netbsd"], "@bazel_tools//src/conditions:windows": [":jni_md_header-windows"], "//conditions:default": [], }), @@ -148,6 +162,7 @@ cc_library( "@bazel_tools//src/conditions:freebsd": ["include/freebsd"], "@bazel_tools//src/conditions:linux": ["include/linux"], "@bazel_tools//src/conditions:openbsd": ["include/openbsd"], + ":netbsd": ["include/netbsd"], "@bazel_tools//src/conditions:windows": ["include/win32"], "//conditions:default": [], }), From 5e5d1e7705210f6433fd1436f7c6c3924f5d0747 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 18 Sep 2026 02:58:39 -0700 Subject: [PATCH 235/251] Add a test for `java_binary` runtime_deps with genrule (ignore-relnotes) PiperOrigin-RevId: 983752195 Change-Id: Ib335e205b93474ced2bb10c6842c3f9d257ea55b --- .../common_launcher_java_binary_tests.bzl | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 5096894c..449e4831 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -520,6 +520,31 @@ def _test_java_binary_runtime_deps_with_transitive_data_impl(env, target): "{workspace}/{package}/some.gss", ]) +def _test_java_binary_runtime_deps_with_genrule(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/langtools"], + ) + util.helper_target( + native.genrule, + name = name + "/langtools", + outs = [name + "/langtools.jar"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_genrule_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_genrule_impl(env, target): + env.expect.that_target(target).runfiles().contains( + "{workspace}/{package}/{test_name}/langtools.jar", + ) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -539,5 +564,6 @@ def java_binary_launcher_tests(name): _test_java_binary_strict_java_deps_flag, _test_java_binary_runtime_deps_transitivity, _test_java_binary_runtime_deps_with_transitive_data, + _test_java_binary_runtime_deps_with_genrule, ], ) From 5368403bc73ee9d7c427478f5100a755dadde8a1 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 21 Sep 2026 04:03:00 -0700 Subject: [PATCH 236/251] Add a test for `java_binary` runtime_deps with native deps (ignore-relnotes) PiperOrigin-RevId: 985173670 Change-Id: Iaba271f8d8fbf2b79a5ca674fa0caf8c950a00fc --- .../common_launcher_java_binary_tests.bzl | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 449e4831..c1e01280 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -545,6 +545,43 @@ def _test_java_binary_runtime_deps_with_genrule_impl(env, target): "{workspace}/{package}/{test_name}/langtools.jar", ) +def _test_java_binary_runtime_deps_with_native_libraries(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Foo.java"], + deps = [name + "/jni.so"], + ) + util.helper_target( + cc_binary, + name = name + "/jni.so", + srcs = ["lib1.so"], + deps = [name + "/helper_library"], + ) + util.helper_target( + cc_library, + name = name + "/helper_library", + srcs = ["lib2.so"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_native_libraries_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_native_libraries_impl(env, target): + env.expect.that_target(target).runfiles().paths().transform( + desc = "basenames", + map_each = lambda f: reversed(f.rsplit("/"))[0], + ).contains_at_least(["lib1.so", "lib2.so"]) + def java_binary_launcher_tests(name): test_suite( name = name, @@ -565,5 +602,6 @@ def java_binary_launcher_tests(name): _test_java_binary_runtime_deps_transitivity, _test_java_binary_runtime_deps_with_transitive_data, _test_java_binary_runtime_deps_with_genrule, + _test_java_binary_runtime_deps_with_native_libraries, ], ) From c796cef2529b7bcd9c51dfe3a651a09fa9b78292 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 22 Sep 2026 05:03:53 -0700 Subject: [PATCH 237/251] Support multiple test sources, `test_classes`, and `non_test_srcs` in `java_test` PiperOrigin-RevId: 985918418 Change-Id: I9600eab4e0221cb6f6ba66be80d7f4d68ccdf160 --- java/bazel/rules/bazel_java_binary.bzl | 12 ++-- java/common/rules/impl/java_binary_impl.bzl | 11 +++- java/common/rules/impl/java_helper.bzl | 38 ++++++++++- java/common/rules/java_binary.bzl | 18 ++++++ test/java/bazel/rules/java_test_tests.bzl | 71 ++++++++++++++++++++- 5 files changed, 138 insertions(+), 12 deletions(-) diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl index 0611e062..998ac898 100644 --- a/java/bazel/rules/bazel_java_binary.bzl +++ b/java/bazel/rules/bazel_java_binary.bzl @@ -79,17 +79,15 @@ def bazel_base_binary_impl(ctx, is_test_rule_class): _java_runtime_version = semantics.find_java_runtime_toolchain(ctx).version if _java_runtime_version >= 17 and _java_runtime_version < 24: jvm_flags.append("-Djava.security.manager=allow") - test_class = ctx.attr.test_class if hasattr(ctx.attr, "test_class") else "" - if test_class == "": - test_class = helper.primary_class(ctx) - if test_class == None: - fail("cannot determine test class. You might want to rename the " + - "rule or add a 'test_class' attribute.") + test_classes = helper.test_classes(ctx) + if not test_classes: + fail("cannot determine test class. You might want to add a " + + "'test_class' or 'test_classes' attribute.") jvm_flags.extend([ "-ea", "-D{prop_name}={prop_value}".format( prop_name = semantics.TEST_SUITE_PROPERTY_NAME, - prop_value = helper.shell_escape(test_class), + prop_value = helper.shell_escape(",".join(test_classes)), ), ]) diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 13718eb8..379c213b 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -87,7 +87,14 @@ def basic_java_binary( if not ctx.attr.use_launcher and (ctx.attr.launcher and ctx.attr.launcher.label != semantics.LAUNCHER_FLAG_LABEL): fail("launcher specified but use_launcher is false") - if not ctx.attr.srcs and ctx.attr.deps: + if not is_test_rule_class: + if hasattr(ctx.attr, "test_classes") and ctx.attr.test_classes: + fail("in %s: 'test_classes' is not allowed on java_binary" % ctx.label) + if hasattr(ctx.attr, "non_test_srcs") and ctx.attr.non_test_srcs: + fail("in %s: 'non_test_srcs' is not allowed on java_binary" % ctx.label) + + srcs = ctx.files.srcs + [src for src in getattr(ctx.files, "non_test_srcs", []) if src not in ctx.files.srcs] + if not srcs and ctx.attr.deps: fail("deps not allowed without srcs; move to runtime_deps?") module_flags = [dep[JavaInfo].module_flags_info for dep in runtime_deps if JavaInfo in dep] @@ -103,7 +110,7 @@ def basic_java_binary( timezone_data = [toolchain._timezone_data] if toolchain._timezone_data else [] target, common_info = basic_java_library( ctx, - srcs = ctx.files.srcs, + srcs = srcs, deps = deps, runtime_deps = runtime_deps, plugins = ctx.attr.plugins, diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 638878ba..2ee5427a 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -88,13 +88,23 @@ def _check_and_get_main_class(ctx): main_class = _primary_class(ctx) return main_class +def _canonical_class_from_target_name(ctx): + return _full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) + def _primary_class(ctx): if ctx.attr.srcs: main = ctx.label.name + ".java" - for src in ctx.files.srcs: + for src in _test_srcs(ctx): if src.basename == main: return _full_classname(_strip_extension(src)) - return _full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) + return _canonical_class_from_target_name(ctx) + +def _test_srcs(ctx): + """Returns ctx.files.srcs excluding any files listed in non_test_srcs.""" + if not hasattr(ctx.files, "non_test_srcs") or not ctx.files.non_test_srcs: + return ctx.files.srcs + non_test_srcs = {src: None for src in ctx.files.non_test_srcs} + return [src for src in ctx.files.srcs if src not in non_test_srcs] def _strip_extension(file): return file.dirname + "/" + ( @@ -106,6 +116,28 @@ def _full_classname(path): java_segments = _loading_phase_helper.java_segments(path) return ".".join(java_segments) if java_segments != None else None +def _test_classes(ctx): + has_test_class = hasattr(ctx.attr, "test_class") and bool(ctx.attr.test_class) + has_test_classes = hasattr(ctx.attr, "test_classes") and bool(ctx.attr.test_classes) + if has_test_class and has_test_classes: + fail("in %s: cannot specify both 'test_class' and 'test_classes'" % ctx.label) + if has_test_class: + return [ctx.attr.test_class] + if has_test_classes: + return ctx.attr.test_classes + if ctx.attr.srcs: + classes = [] + for src in _test_srcs(ctx): + if src.extension == "java": + cls = _full_classname(_strip_extension(src)) + if cls == None: + return [] + classes.append(cls) + if classes: + return classes + canonical = _canonical_class_from_target_name(ctx) + return [canonical] if canonical != None else [] + def _concat(*lists): result = [] for list in lists: @@ -256,6 +288,8 @@ helper = struct( launcher_artifact_for_target = _launcher_artifact_for_target, check_and_get_main_class = _check_and_get_main_class, primary_class = _primary_class, + test_classes = _test_classes, + test_srcs = _test_srcs, strip_extension = _strip_extension, concat = _concat, get_shared_native_deps_path = _get_shared_native_deps_path, diff --git a/java/common/rules/java_binary.bzl b/java/common/rules/java_binary.bzl index 609ca974..12250ab0 100644 --- a/java/common/rules/java_binary.bzl +++ b/java/common/rules/java_binary.bzl @@ -357,6 +357,24 @@ The Java class to be loaded by the test runner.
behavior differs in each case, such as running a different subset of the tests. This attribute also enables the use of Java tests outside the javatests tree. +

+ """, + ), + "test_classes": attr.string_list( + doc = """ +The Java classes to be loaded by the test runner. +

+ By default, test classes are automatically inferred from source file names in + srcs. +

+

+ Specify test_classes explicitly when: +

    +
  • The classes to run cannot be inferred from the source file names or do not + match the package path convention.
  • +
  • Only a specific subset of test classes compiled into the binary should be executed.
  • +
  • Test suites or base test classes are defined elsewhere.
  • +

""", ), diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl index 5c76b0ee..f01d6dcc 100644 --- a/test/java/bazel/rules/java_test_tests.bzl +++ b/test/java/bazel/rules/java_test_tests.bzl @@ -1,11 +1,17 @@ """Tests for the Bazel java_test rule""" +load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_test.bzl", "java_test") +load("//test/java/testutil:helper.bzl", "always_passes") def _test_deduced_test_class(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + util.helper_target( java_test, name = name + "/foo", @@ -16,6 +22,7 @@ def _test_deduced_test_class(name): name = name, impl = _test_deduced_test_class_impl, target = name + "/foo", + attr_values = {"tags": ["min_bazel_8"]}, ) def _test_deduced_test_class_impl(env, target): @@ -32,7 +39,7 @@ def _test_deduced_test_class_impl(env, target): # Windows assert_jvm_flags = assert_action.argv() assert_jvm_flags.contains_predicate( - matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.foo"), + matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.Foo"), ) # regression test for https://github.com/bazelbuild/bazel/issues/20378 @@ -49,11 +56,73 @@ def _test_invalid_test_class_at_repo_root_impl(env, target): matching.str_matches("cannot determine test class."), ) +def _test_test_classes(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_test, + name = name + "/foo", + test_classes = ["com.example.FooTest", "com.example.BarTest"], + ) + + analysis_test( + name = name, + impl = _test_test_classes_impl, + target = name + "/foo", + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_test_classes_impl(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + assert_action = env.expect.that_target(target).action_generating(executable) + + if assert_action.actual.substitutions: + # TemplateExpansion action on linux/mac + assert_jvm_flags = assert_action.substitutions().get( + "%jvm_flags%", + factory = lambda v, meta: subjects.collection([v], meta), + ) + else: + # Windows + assert_jvm_flags = assert_action.argv() + assert_jvm_flags.contains_predicate( + matching.str_matches("-Dbazel.test_suite=com.example.FooTest,com.example.BarTest"), + ) + +def _test_both_test_class_and_test_classes_fails(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_test, + name = name + "/foo", + test_class = "FooTest", + test_classes = ["FooTest"], + ) + + analysis_test( + name = name, + impl = _test_both_test_class_and_test_classes_fails_impl, + target = name + "/foo", + expect_failure = True, + attr_values = {"tags": ["min_bazel_8"]}, + ) + +def _test_both_test_class_and_test_classes_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("cannot specify both 'test_class' and 'test_classes'"), + ) + def java_test_tests(name): test_suite( name = name, tests = [ _test_deduced_test_class, _test_invalid_test_class_at_repo_root, + _test_test_classes, + _test_both_test_class_and_test_classes_fails, ], ) From 92e1079bc5bf6e5edd54e8373165dcf8dcd374a9 Mon Sep 17 00:00:00 2001 From: Matthew Gharrity Date: Wed, 23 Sep 2026 11:25:25 -0700 Subject: [PATCH 238/251] Fix native library path separator on Windows (#383) On Windows, java.library.path is split by ";" instead of ":". Regression test added. Note for Googlers: this fix is in service of b/149162146#comment19 Closes #383 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/383 from gharrma:fix-java-native-lib-handling-on-windows b0e4c3efbe33f23d05145001ca9df54ba4c6e7ed PiperOrigin-RevId: 986888472 Change-Id: I492266c118fba328e651accf005c0ba7945ed0a3 --- java/common/rules/impl/java_binary_impl.bzl | 3 +- .../common_launcher_java_binary_tests.bzl | 42 +++++++++++++++++++ .../testutil/binary_executable_subject.bzl | 8 ++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 379c213b..691d66d2 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -169,8 +169,9 @@ def basic_java_binary( native_libs_dirs = collect_native_deps_dirs(depset(transitive = native_libs_depsets)) if native_libs_dirs: prefix = "${JAVA_RUNFILES}/" + ctx.workspace_name + "/" + separator = ";" if helper.is_target_platform_windows(ctx) else ":" jvm_flags.append("-Djava.library.path=%s" % ( - ":".join([prefix + d for d in native_libs_dirs]) + separator.join([prefix + d for d in native_libs_dirs]) )) jvm_flags.extend(ctx.fragments.java.default_jvm_opts) diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index c1e01280..ec403a0a 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -276,6 +276,47 @@ def _test_java_binary_native_library_path_includes_transitive_deps_impl(env, tar "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/jni.so___{package}", ]) +# Regression test: the native library path separator on Windows is ";" instead of ":". +def _test_java_binary_native_library_path_separator(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["DoesNotMatter.java"], + deps = [ + name + "/lib1", + name + "/lib2", + ], + ) + + # Define two native libs (in different directories so java.library.path has multiple entries). + util.helper_target( + cc_binary, + name = name + "/lib1", + srcs = ["lib1.so"], + ) + util.helper_target( + cc_binary, + name = name + "/lib2", + srcs = ["subdir/lib2.so"], + ) + + analysis_test( + name = name, + # The Starlark rules are only used with Bazel 8 onwards. + attr_values = {"tags": ["min_bazel_8"]}, + attrs = { + "_windows_constraints": attr.label_list(default = ["@platforms//os:windows"]), + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + }, + impl = _test_java_binary_native_library_path_separator_impl, + target = name + "/app", + ) + +def _test_java_binary_native_library_path_separator_impl(env, target): + # We should find two libraries on java.library.path (if the correct path separator was used). + native_library_paths = expect_that_executable.of_target(env, target).native_library_paths() + native_library_paths.has_size(2) + # Regression test for bug 2774317: Problems with inner classes as main class. def _test_java_binary_inner_class(name): util.helper_target( @@ -596,6 +637,7 @@ def java_binary_launcher_tests(name): _test_java_test_main_class_with_dot, _test_java_test_has_assertions_enabled, _test_java_binary_native_library_path_includes_transitive_deps, + _test_java_binary_native_library_path_separator, _test_java_binary_inner_class, _test_java_test_inner_class, _test_java_binary_strict_java_deps_flag, diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl index df5c4774..29df32d0 100644 --- a/test/java/testutil/binary_executable_subject.bzl +++ b/test/java/testutil/binary_executable_subject.bzl @@ -3,6 +3,7 @@ load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_testing//lib:truth.bzl", "subjects") load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") def _of_target(env, target): executable = target[DefaultInfo].files_to_run.executable.short_path @@ -11,7 +12,7 @@ def _of_target(env, target): java_start_class = lambda: _java_start_class_subject(action_subject), test_suite = lambda: _test_suite_subject(action_subject), jvm_flags = lambda: _jvm_flags_subject(action_subject), - native_library_paths = lambda: _native_library_paths_subject(action_subject), + native_library_paths = lambda: _native_library_paths_subject(env, action_subject), ) return public @@ -44,7 +45,8 @@ def _jvm_flags_subject(action): desc = "jvm_flags", ).offset(0, factory = subjects.str).split("\t") -def _native_library_paths_subject(action): +def _native_library_paths_subject(env, action): + separator = ";" if helper.is_target_platform_windows(env.ctx) else ":" return _jvm_flags_subject(action).transform( filter = lambda e: e.startswith("-Djava.library.path="), map_each = lambda e: e.split("=", 1)[1], @@ -54,7 +56,7 @@ def _native_library_paths_subject(action): factory = lambda actual, meta: subjects.str(actual, meta.derive( format_str_kwargs = {"cpu": meta.ctx.attr._cc_toolchain[cc_common.CcToolchainInfo].cpu}, )), - ).split(":").transform( + ).split(separator).transform( map_each = lambda e: e.replace("_U", "_").replace("_S", "/").replace("_C", ":"), desc = "pretty", format = True, From fa3e5acdca3f03b8260eb54bce2754f9c3f1f86b Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 25 Sep 2026 02:13:56 -0700 Subject: [PATCH 239/251] Drop deprecated aliases from `defs.bzl` PiperOrigin-RevId: 988125555 Change-Id: I6a06ab130ec27dbf0e39bae1f4e6100df8539932 --- java/defs.bzl | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/java/defs.bzl b/java/defs.bzl index 8899a705..2034bf45 100644 --- a/java/defs.bzl +++ b/java/defs.bzl @@ -13,8 +13,6 @@ # limitations under the License. """Starlark rules for building Java projects.""" -load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library") -load("@com_google_protobuf//bazel:java_proto_library.bzl", _java_proto_library = "java_proto_library") load("//java:java_binary.bzl", _java_binary = "java_binary") load("//java:java_import.bzl", _java_import = "java_import") load("//java:java_library.bzl", _java_library = "java_library") @@ -41,26 +39,6 @@ java_runtime = _java_runtime java_toolchain = _java_toolchain java_package_configuration = _java_package_configuration -# Proto rules -# Deprecated: don't use java proto libraries from here -def java_proto_library(**kwargs): - if "deprecation" not in kwargs: - _java_proto_library( - deprecation = "Use java_proto_library from @com_google_protobuf//bazel:java_proto_library.bzl", - **kwargs - ) - else: - _java_proto_library(**kwargs) - -def java_lite_proto_library(**kwargs): - if "deprecation" not in kwargs: - _java_lite_proto_library( - deprecation = "Use java_lite_proto_library from @com_google_protobuf//bazel:java_lite_proto_library.bzl", - **kwargs - ) - else: - _java_lite_proto_library(**kwargs) - # Modules and providers JavaInfo = _JavaInfo From b3a5a482d62c6b9d6f5ae06313baea43f63ea045 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 26 Sep 2026 07:32:18 -0700 Subject: [PATCH 240/251] Add and enforce allowlists for `java_test` `non_test_srcs`, `test_classes`, and `test_class` PiperOrigin-RevId: 988840734 Change-Id: Icd8b787a487492d87064b7c3b8f3a6fd12cd722e --- java/common/rules/java_binary.bzl | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/java/common/rules/java_binary.bzl b/java/common/rules/java_binary.bzl index 12250ab0..8c0e00ed 100644 --- a/java/common/rules/java_binary.bzl +++ b/java/common/rules/java_binary.bzl @@ -337,10 +337,12 @@ The Java class to be loaded by the test runner.

This attribute specifies the name of a Java class to be run by this test. It is rare to need to set this. If this argument is omitted, - it will be inferred using the target's name and its - source-root-relative path. If the test is located outside a known - source root, Bazel will report an error if test_class - is unset. + the test classes will be inferred from srcs if present, or + otherwise inferred using the target's name and its + source-root-relative path (which is discouraged; when srcs is + empty, prefer setting test_class explicitly). If the test is + located outside a known source root, Bazel will report an error if + test_class is unset.

For JUnit3, the test class needs to either be a subclass of @@ -365,16 +367,18 @@ The Java class to be loaded by the test runner.
The Java classes to be loaded by the test runner.

By default, test classes are automatically inferred from source file names in - srcs. + srcs. Setting test_classes is generally discouraged: + prefer listing test sources directly in srcs and omitting + test_classes. In particular, specifying test_classes + when srcs is non-empty is discouraged, and placing test sources in + a separate java_library with test_classes risks + silently skipping newly added test files unless they are also manually listed + in test_classes.

- Specify test_classes explicitly when: -

    -
  • The classes to run cannot be inferred from the source file names or do not - match the package path convention.
  • -
  • Only a specific subset of test classes compiled into the binary should be executed.
  • -
  • Test suites or base test classes are defined elsewhere.
  • -
+ Specify test_classes only when srcs is empty and the + test target runs multiple pre-compiled test classes from deps or + runtime_deps.

""", ), From b42f7122d097d60de066f7d26233a45a7acd19f7 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 30 Sep 2026 04:09:19 -0700 Subject: [PATCH 241/251] Update `rules_cc` dep to `0.2.25` An upcoming change requires a release that contains https://github.com/bazelbuild/rules_cc/commit/ebe56324a069b05c9de2d22a47511ad76e3b0a86 (ignore-relnotes) PiperOrigin-RevId: 990894729 Change-Id: I0fe3db122e97e27749a3b7864908db8d83f23a51 --- MODULE.bazel | 2 +- java/common/BUILD | 1 + java/common/rules/impl/BUILD | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6135ff78..b11bd664 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,7 +6,7 @@ module( ) bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "rules_cc", version = "0.2.17") +bazel_dep(name = "rules_cc", version = "0.2.25") bazel_dep(name = "bazel_features", version = "1.30.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf") diff --git a/java/common/BUILD b/java/common/BUILD index 7887b1f0..096f77b8 100644 --- a/java/common/BUILD +++ b/java/common/BUILD @@ -38,6 +38,7 @@ bzl_library( visibility = ["//visibility:public"], deps = [ "@bazel_features//:features", + "@rules_cc//cc:action_names_bzl", "@rules_cc//cc/common:cc_helper_bzl", ], ) diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index a6eb44ba..ed1eb2f7 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -21,6 +21,7 @@ bzl_library( deps = [ ":java_helper_bzl", "//java/common:proguard_spec_info_bzl", + "@rules_cc//cc:action_names_bzl", # TODO: remove after https://github.com/bazelbuild/rules_cc/issues/913 is fixed "@rules_cc//cc/common:cc_helper_bzl", ], ) From f0d277a1b71f11b6e9c07cfde489a7d3b700bcf4 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 1 Oct 2026 04:18:28 -0700 Subject: [PATCH 242/251] Drop `compatibility_level` from `rules_java` Deprecated and no-op in all Bazel versions. PiperOrigin-RevId: 991583335 Change-Id: Id40bb1853ab9f4fdd30bfcda28c7a7b5d6b8ad19 --- MODULE.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index b11bd664..556f7c5a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -2,7 +2,6 @@ module( name = "rules_java", version = "0.0.0", bazel_compatibility = [">=7.0.0"], - compatibility_level = 1, ) bazel_dep(name = "platforms", version = "0.0.11") From 2265f22fd8615b8427df587937c04a18ac4938e4 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 2 Oct 2026 02:30:45 -0700 Subject: [PATCH 243/251] Starlarkify `collect_native_deps_dirs` This is an ~exact transliteration of https://github.com/bazelbuild/bazel/blob/4e0cdee77065995b0acdadc0fb75a277880844f2/src/main/java/com/google/devtools/build/lib/rules/java/JavaStarlarkCommon.java#L295-L333 Once this lands in a rules_java release and Bazel uses that version, the native code can be deleted. PiperOrigin-RevId: 992197433 Change-Id: Ifaa2eaab91312c697f04e71273c1a89fe33a1a75 --- java/common/rules/impl/java_binary_impl.bzl | 19 +++++++++++++++++-- java/private/java_common_internal.bzl | 11 ----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 691d66d2..6308ec32 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -22,7 +22,6 @@ load("//java/common/rules/impl:basic_java_library_impl.bzl", "basic_java_library load("//java/private:java_common.bzl", "java_common") load( "//java/private:java_common_internal.bzl", - "collect_native_deps_dirs", "get_runtime_classpath_for_archive", ) load("//java/private:java_info.bzl", "JavaCompilationInfo", "JavaInfo", "to_java_binary_info") @@ -166,7 +165,7 @@ def basic_java_binary( native_libs_depsets.append(dep[CcInfo]._legacy_transitive_native_libraries) else: native_libs_depsets.append(dep[CcInfo].transitive_native_libraries()) - native_libs_dirs = collect_native_deps_dirs(depset(transitive = native_libs_depsets)) + native_libs_dirs = _collect_native_deps_dirs(depset(transitive = native_libs_depsets)) if native_libs_dirs: prefix = "${JAVA_RUNFILES}/" + ctx.workspace_name + "/" separator = ";" if helper.is_target_platform_windows(ctx) else ":" @@ -469,6 +468,22 @@ def _auto_create_deploy_jar(ctx, info, launcher_info, main_class, coverage_main_ ) return output +def _collect_native_deps_dirs(libraries): + result = {} + for library_to_link in libraries.to_list(): + candidate = None + if library_to_link.interface_library: + candidate = library_to_link.interface_library + elif library_to_link.dynamic_library: + candidate = library_to_link.dynamic_library + if candidate: + ext = "." + candidate.extension + if ext in cc_helper.extensions.INTERFACE_SHARED_LIBRARY: + continue + parent_dir = candidate.short_path[:-(1 + len(candidate.basename))] + result[parent_dir] = None + return result.keys() + def _test_providers(ctx): test_providers = [] if helper.has_target_constraints(ctx, ctx.attr._apple_constraints): diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl index 30d9533c..4c5b6035 100644 --- a/java/private/java_common_internal.bzl +++ b/java/private/java_common_internal.bzl @@ -507,17 +507,6 @@ def target_kind(target): """ return get_internal_java_common().target_kind(target) -def collect_native_deps_dirs(libraries): - """Collect the set of root-relative paths containing native libraries - - Args: - libraries: (depset[LibraryToLink]) set of native libraries - - Returns: - ([String]) A set of root-relative paths as a list - """ - return get_internal_java_common().collect_native_deps_dirs(libraries) - def get_runtime_classpath_for_archive(jars, excluded_jars): """Filters a classpath to remove certain entries From b63c8a11c3a84dc4dcf3405cbb390a5d178b5be1 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 6 Oct 2026 01:51:37 -0700 Subject: [PATCH 244/251] Drop support for Bazel 7 PiperOrigin-RevId: 994238467 Change-Id: I4c894b2f5a325a7b17fb8145c7f6f06d32aa4928 --- .bazelci/presubmit.yml | 11 +---------- .bcr/presubmit.yml | 1 - MODULE.bazel | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index e9d03fa6..9c186288 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -27,7 +27,7 @@ buildifier: latest matrix: all_platforms: ["rockylinux8_arm64", "ubuntu2404", "macos", "macos_arm64", "windows"] - bazel: ["7.x", "8.x", "9.x", "last_green"] + bazel: ["8.x", "9.x", "last_green"] modern_bazel: ["9.x", "last_green", "rolling"] # Fully supported Bazel versions tasks: @@ -47,15 +47,6 @@ tasks: test_targets: *test_targets test_flags: - "--test_tag_filters=-min_bazel_9" -# Bazel 7.x - build_and_test_bazel7: - name: "Bazel 7.x" - bazel: "7.x" - platform: ${{ all_platforms }} - build_targets: *build_targets - test_targets: *test_targets - test_flags: - - "--test_tag_filters=-min_bazel_8,-min_bazel_9" # Integration tests integration_build_and_test: diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 6d221348..c26fb618 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -6,7 +6,6 @@ matrix: - ubuntu2004 - windows bazel: - - 7.x - 8.x - 9.x tasks: diff --git a/MODULE.bazel b/MODULE.bazel index 556f7c5a..13d44ed5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,7 @@ module( name = "rules_java", version = "0.0.0", - bazel_compatibility = [">=7.0.0"], + bazel_compatibility = [">=8.0.0"], ) bazel_dep(name = "platforms", version = "0.0.11") From d3159af187d1fd311f8af94afb88c4f21c2454f4 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 7 Oct 2026 00:36:15 -0700 Subject: [PATCH 245/251] Clean up references to the `min_bazel_8` tag No longer needed after https://github.com/bazelbuild/rules_java/commit/b63c8a11c3a84dc4dcf3405cbb390a5d178b5be1 (ignore-relnotes) PiperOrigin-RevId: 994907052 Change-Id: Id4858027032c71974e18b7109b64fdb9980856fe --- test/java/bazel/common/java_common_tests.bzl | 2 -- test/java/bazel/rules/java_binary_tests.bzl | 4 ---- test/java/bazel/rules/java_import_tests.bzl | 2 -- test/java/bazel/rules/java_library_tests.bzl | 2 -- test/java/bazel/rules/java_plugin_tests.bzl | 2 -- test/java/bazel/rules/java_test_tests.bzl | 3 --- test/java/common/java_common_tests.bzl | 2 -- test/java/common/java_info_tests.bzl | 4 ---- .../java/common/rules/common_launcher_java_binary_tests.bzl | 5 ----- test/java/common/rules/deploy_archive_builder_tests.bzl | 2 -- test/java/common/rules/java_binary_tests.bzl | 2 -- test/java/common/rules/java_import_tests.bzl | 6 ------ test/java/common/rules/java_plugin_tests.bzl | 2 -- test/java/common/rules/java_single_jar_tests.bzl | 1 - test/java/toolchains/java_toolchain_tests.bzl | 4 ---- 15 files changed, 43 deletions(-) diff --git a/test/java/bazel/common/java_common_tests.bzl b/test/java/bazel/common/java_common_tests.bzl index 80fdf442..9702f735 100644 --- a/test/java/bazel/common/java_common_tests.bzl +++ b/test/java/bazel/common/java_common_tests.bzl @@ -20,8 +20,6 @@ def _test_java_common_pack_sources_with_external_resource(name): name = name, impl = _test_java_common_pack_sources_with_external_resource_impl, target = name + "/custom", - # Bazel 7 names external repos differently - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_common_pack_sources_with_external_resource_impl(env, target): diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index a36a9116..39bd787d 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -67,7 +67,6 @@ def _test_java_binary_excludes_build_data(name): name = name, impl = _test_java_binary_excludes_build_data_impl, target = name + "/bin", - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_binary_excludes_build_data_impl(env, target): @@ -103,7 +102,6 @@ def _test_java_binary_stamping_enabled_build_data_excluded_fails(name): impl = _test_java_binary_stamping_enabled_build_data_excluded_fails_impl, target = name + "/bin", expect_failure = True, - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_binary_stamping_enabled_build_data_excluded_fails_impl(env, target): @@ -131,8 +129,6 @@ def _test_java_binary_javacopts_make_variable_expansion(name): name = name, impl = _test_java_binary_javacopts_make_variable_expansion_impl, target = name + "/bin", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_binary_javacopts_make_variable_expansion_impl(env, target): diff --git a/test/java/bazel/rules/java_import_tests.bzl b/test/java/bazel/rules/java_import_tests.bzl index 8ea3ff2e..e368b14a 100644 --- a/test/java/bazel/rules/java_import_tests.bzl +++ b/test/java/bazel/rules/java_import_tests.bzl @@ -21,8 +21,6 @@ def _test_import_deps_checker_checking_mode(name): name = name, impl = _test_import_deps_checker_checking_mode_impl, target = name + "/import-jar", - # The rules_java Starlark implementation is used from Bazel 8 on. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_import_deps_checker_checking_mode_impl(env, target): diff --git a/test/java/bazel/rules/java_library_tests.bzl b/test/java/bazel/rules/java_library_tests.bzl index 770fbe60..fd20980d 100644 --- a/test/java/bazel/rules/java_library_tests.bzl +++ b/test/java/bazel/rules/java_library_tests.bzl @@ -26,8 +26,6 @@ def _test_java_library_javacopts_make_variable_expansion(name): name = name, impl = _test_java_library_javacopts_make_variable_expansion_impl, target = name + "/lib", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_library_javacopts_make_variable_expansion_impl(env, target): diff --git a/test/java/bazel/rules/java_plugin_tests.bzl b/test/java/bazel/rules/java_plugin_tests.bzl index 4df4bcca..9015ebf1 100644 --- a/test/java/bazel/rules/java_plugin_tests.bzl +++ b/test/java/bazel/rules/java_plugin_tests.bzl @@ -25,8 +25,6 @@ def _test_java_plugin_javacopts_make_variable_expansion(name): name = name, impl = _test_java_plugin_javacopts_make_variable_expansion_impl, target = name + "/plug", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_plugin_javacopts_make_variable_expansion_impl(env, target): diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl index f01d6dcc..5955a92e 100644 --- a/test/java/bazel/rules/java_test_tests.bzl +++ b/test/java/bazel/rules/java_test_tests.bzl @@ -22,7 +22,6 @@ def _test_deduced_test_class(name): name = name, impl = _test_deduced_test_class_impl, target = name + "/foo", - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_deduced_test_class_impl(env, target): @@ -71,7 +70,6 @@ def _test_test_classes(name): name = name, impl = _test_test_classes_impl, target = name + "/foo", - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_test_classes_impl(env, target): @@ -108,7 +106,6 @@ def _test_both_test_class_and_test_classes_fails(name): impl = _test_both_test_class_and_test_classes_fails_impl, target = name + "/foo", expect_failure = True, - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_both_test_class_and_test_classes_fails_impl(env, target): diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index 0a3b257c..e9942abd 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -782,8 +782,6 @@ def _test_compile_strict_deps_enum(name): impl = _test_compile_strict_deps_enum_impl, target = name + "/custom", expect_failure = True, - # This is a crash in earlier Bazel versions (i.e. native rules) - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_compile_strict_deps_enum_impl(env, target): diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index daea0485..8f4c2c13 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -1130,8 +1130,6 @@ def _transitive_native_libraries_test(name): name = name, impl = _transitive_native_libraries_test_impl, target = target_name, - # LibraryToLink.library_indentifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _transitive_native_libraries_test_impl(env, target): @@ -1191,8 +1189,6 @@ def _native_libraries_propagation_test(name): name = name, impl = _native_libraries_propagation_test_impl, target = target_name, - # LibraryToLink.library_identifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _native_libraries_propagation_test_impl(env, target): diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index ec403a0a..0a83d9c6 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -58,7 +58,6 @@ def _test_java_binary_resources_only(name): analysis_test( name = name, - attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, @@ -94,7 +93,6 @@ def _test_java_binary_deploy_jar_coverage_setup(name): analysis_test( name = name, - attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 config_settings = { "//command_line_option:collect_code_coverage": True, }, @@ -302,8 +300,6 @@ def _test_java_binary_native_library_path_separator(name): analysis_test( name = name, - # The Starlark rules are only used with Bazel 8 onwards. - attr_values = {"tags": ["min_bazel_8"]}, attrs = { "_windows_constraints": attr.label_list(default = ["@platforms//os:windows"]), "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), @@ -479,7 +475,6 @@ def _test_java_binary_runtime_deps_transitivity(name): analysis_test( name = name, - attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 impl = _test_java_binary_runtime_deps_transitivity_impl, targets = { "b1": name + "/b1", diff --git a/test/java/common/rules/deploy_archive_builder_tests.bzl b/test/java/common/rules/deploy_archive_builder_tests.bzl index 727790f8..57d3035a 100644 --- a/test/java/common/rules/deploy_archive_builder_tests.bzl +++ b/test/java/common/rules/deploy_archive_builder_tests.bzl @@ -25,8 +25,6 @@ def _test_custom_singlejar(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - # Starlark rules are only used with Bazel 8 onwards. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_custom_singlejar_impl(env, target): diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index 8b688e11..6ee32ba3 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -47,8 +47,6 @@ def _test_stamp_conversion_does_not_override_int(name): config_settings = { "//command_line_option:stamp": False, }, - # deploy jars are in a separate rule in Bazel 7, Bazel 6 generated build-info differently - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_stamp_conversion_does_not_override_int_impl(env, target): diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl index c74bd3de..ead39e4c 100644 --- a/test/java/common/rules/java_import_tests.bzl +++ b/test/java/common/rules/java_import_tests.bzl @@ -209,8 +209,6 @@ def _test_compile_jdeps_propagated_for_deps(name): "with_deps": name + "/import-jar", "without_deps": name + "/depjar", }, - # The rules_java Starlark implementation is used from Bazel 8 on. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_compile_jdeps_propagated_for_deps_impl(env, targets): @@ -350,8 +348,6 @@ def _test_srcjar_added_to_validation_output_group(name): name = name, impl = _test_srcjar_added_to_validation_output_group_impl, target = name + "/libraryjar_with_srcjar", - # Starlark rules are only used with Bazel 8 onwards. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_srcjar_added_to_validation_output_group_impl(env, target): @@ -920,8 +916,6 @@ def _test_transitive_proguard_specs_are_exported(name): name = name, impl = _test_transitive_proguard_specs_are_exported_impl, target = target_name, - # Before Bazel 8, native rules use the native ProguardSpecProvider - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_transitive_proguard_specs_are_exported_impl(env, target): diff --git a/test/java/common/rules/java_plugin_tests.bzl b/test/java/common/rules/java_plugin_tests.bzl index 71c2d156..b6e48610 100644 --- a/test/java/common/rules/java_plugin_tests.bzl +++ b/test/java/common/rules/java_plugin_tests.bzl @@ -194,8 +194,6 @@ def _test_java_plugin_exports_transitive_proguard_specs(name): name = name, impl = _test_java_plugin_exports_transitive_proguard_specs_impl, target = name + "/top", - # Before Bazel 8, native rules use the native ProguardSpecProvider - attr_values = {"tags": ["min_bazel_8"]}, provider_subject_factories = [struct( type = ProguardSpecInfo, name = "ProguardInfo", diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index c2237e73..87c92463 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -318,7 +318,6 @@ def _test_java_binary_deploy_env_with_java_single_jar(name): _analysis_test( name = name, - attr_values = {"tags": ["min_bazel_8"]}, # the deploy jar was created by a separate rule in Bazel 7 impl = _test_java_binary_deploy_env_with_java_single_jar_impl, target = name + "_bin", ) diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 099b5e42..af4e69c3 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -111,8 +111,6 @@ def _test_singlejar_get_command_line(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - # This crashes in earlier Bazel versions where native rules handled deploy jars differently. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_singlejar_get_command_line_impl(env, target): @@ -697,7 +695,6 @@ def _test_default_javac_opts_depset(name): name = name, impl = _test_default_javac_opts_depset_impl, target = name + "/alias", - attr_values = {"tags": ["min_bazel_8"]}, config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, @@ -727,7 +724,6 @@ def _test_default_javac_opts(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_default_javac_opts_impl(env, target): From b74de71517fc9f27913fa85d677a716f0bd1d549 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 12 Oct 2026 03:15:20 -0700 Subject: [PATCH 246/251] Update `java_tools` to `v22.0` Also update an integration test toolchain since Turbine now requires jdk 25. PiperOrigin-RevId: 997802656 Change-Id: I71ee05b38977de282c9988b52c11c8633ccbf3e5 --- java/repositories.bzl | 40 ++++++++++++++++++++-------------------- test/repo/MODULE.bazel | 6 +++--- test/repo/WORKSPACE | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/java/repositories.bzl b/java/repositories.bzl index 007d934c..bfa229a7 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,39 +22,39 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v21.0", - "source_revision": "1ec21d9228a9b0aad0acfbf812f62e13f6addb88", + "version": "v22.0", + "source_revision": "c9b10ec53b5fa49a1bb9c593f08f73ff52f60d95", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_linux-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_linux-v21.0.zip", - "sha": "cf585d7dddf524672815bb09d92bcc8a54f55e5ee7b7e5c862756b6e5ef1be1d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_linux-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_linux-v22.0.zip", + "sha": "b0b3c2873f30c1123cdd77a74f89fcc4d4debc09a70c8619a4fe8e322f7fda96", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_linux_aarch64-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_linux_aarch64-v21.0.zip", - "sha": "e44592d23b88a6773f558a7b19437f42d3fe72cef02a2d3da591c0e304b5cc8d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_linux_aarch64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_linux_aarch64-v22.0.zip", + "sha": "f0899527a8784ea0510801a3ee27b3276e2bb78e599473999fe88585a505ddd3", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_windows-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_windows-v21.0.zip", - "sha": "6dc3eba1567b700622e77523af397a9d2fb314706243318981459a1e980abe3a", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_windows-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_windows-v22.0.zip", + "sha": "1b302daf293b9ec15eaa2705581976e8c5fd91153fabc6a939a043e6c3d9cf90", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_darwin_x86_64-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_darwin_x86_64-v21.0.zip", - "sha": "b90f87567c542fae93d2c24bfe65c01ae3c06b236926df863a70b0a99202f2e4", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_darwin_x86_64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_darwin_x86_64-v22.0.zip", + "sha": "fd5d51572f9e2911ae1564849e011805b328f982587e3aaed034f363d646452f", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools_darwin_arm64-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools_darwin_arm64-v21.0.zip", - "sha": "fcac51b9198e16bb0f3eaa583efc584cb87df9c22eb637b3e64a54d2998653ca", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_darwin_arm64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_darwin_arm64-v22.0.zip", + "sha": "0c78a0d00f09867d56a5064857c936370dab257e5d29dc8d875825509460a456", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v21.0/java_tools-v21.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v21.0/java_tools-v21.0.zip", - "sha": "a0017111e49727f54e7e0d684e69735d3ac79abe933de2aef8577b2808cbbe46", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools-v22.0.zip", + "sha": "b13ee1eaa8681d3ec4faffab4251902a0c1b5135b1f5c718831fc5798db82f9b", }, }, } diff --git a/test/repo/MODULE.bazel b/test/repo/MODULE.bazel index 5f300800..5fdac278 100644 --- a/test/repo/MODULE.bazel +++ b/test/repo/MODULE.bazel @@ -54,15 +54,15 @@ custom_jdk = use_extension("@rules_java//java:extensions.bzl", "java_repository" custom_jdk.remote( name = "my_funky_jdk", prefix = "funky", - strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64", + strip_prefix = "zulu25.36.205-ca-jdk25.0.4.1-linux_x64", target_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], urls = [ - "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu25.36.205-ca-jdk25.0.4.1-linux_x64.tar.gz", ], - version = "24", + version = "25", ) use_repo(custom_jdk, "my_funky_jdk", "my_funky_jdk_toolchain_config_repo") diff --git a/test/repo/WORKSPACE b/test/repo/WORKSPACE index 32cadb59..a100961e 100644 --- a/test/repo/WORKSPACE +++ b/test/repo/WORKSPACE @@ -60,15 +60,15 @@ load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_reposito remote_java_repository( name = "my_funky_jdk", prefix = "funky", - strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64", + strip_prefix = "zulu25.36.205-ca-jdk25.0.4.1-linux_x64", target_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], urls = [ - "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu25.36.205-ca-jdk25.0.4.1-linux_x64.tar.gz", ], - version = "24", + version = "25", ) register_toolchains("@my_funky_jdk_toolchain_config_repo//:all") From b31212208a21aae095f488fe3c2d509b1ddec828 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 13 Oct 2026 02:38:09 -0700 Subject: [PATCH 247/251] Add `android_lint_tools` to `java_toolchain` for `AndroidLint` action `tools`. `_android_lint_action` in `android_lint.bzl` passes `linter.data` (`android_lint_data`, used for `android_lint_opts` location expansion) in per-action `inputs` (`transitive_inputs`) rather than `tools`. Add `android_lint_tools` on `java_toolchain` for `android_lint_jvm_opts` location expansion and include `linter.tools` in `AndroidLint` action `tools`, so persistent workers include JVM startup tool files in `WorkerFilesHash` without rebuilding worker snapshots when per-action `android_lint_data` inputs change. PiperOrigin-RevId: 998493863 Change-Id: I97d05f2e3d10f0948fc0563551f2c098c743d35a --- java/common/rules/android_lint.bzl | 4 ++-- java/common/rules/java_toolchain.bzl | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/java/common/rules/android_lint.bzl b/java/common/rules/android_lint.bzl index 7152990c..d07bb5e3 100644 --- a/java/common/rules/android_lint.bzl +++ b/java/common/rules/android_lint.bzl @@ -82,7 +82,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li executable = linter.tool.executable transitive_inputs = [] if executable.extension != "jar": - tools = [linter.tool] + tools = [linter.tool, linter.tools] transitive_inputs.append(linter.data) args_list = [args] else: @@ -91,7 +91,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li jvm_args.add_all(linter.jvm_opts) jvm_args.add("-jar", executable) executable = java_runtime.java_executable_exec_path - tools = [java_runtime.files, linter.tool.executable] + tools = [java_runtime.files, linter.tool.executable, linter.tools] transitive_inputs.append(linter.data) args_list = [jvm_args, args] diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index a24ae4f1..12050839 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -176,8 +176,9 @@ def _get_android_lint_tool(ctx): fail(ctx.attr.android_lint_runner.label, "does not refer to a valid executable target") return struct( tool = files_to_run, + tools = depset(ctx.files.android_lint_tools), data = depset(ctx.files.android_lint_data), - jvm_opts = depset([ctx.expand_location(opt, ctx.attr.android_lint_data) for opt in ctx.attr.android_lint_jvm_opts]), + jvm_opts = depset([ctx.expand_location(opt, ctx.attr.android_lint_tools) for opt in ctx.attr.android_lint_jvm_opts]), lint_opts = [ctx.expand_location(opt, ctx.attr.android_lint_data) for opt in ctx.attr.android_lint_opts], package_config = [dep[JavaPackageConfigurationInfo] for dep in ctx.attr.android_lint_package_configuration], ) @@ -297,6 +298,13 @@ java_toolchain( cfg = "exec", allow_files = True, doc = """ +Labels of files available for label-expansion in android_lint_opts. + """, + ), + "android_lint_tools": attr.label_list( + cfg = "exec", + allow_files = True, + doc = """ Labels of tools available for label-expansion in android_lint_jvm_opts. """, ), From ceb99dc11376c33ea316f1afaea32f103781cfc9 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 15 Oct 2026 02:33:20 -0700 Subject: [PATCH 248/251] Handle `third_party/java/` nested source roots in `_java_segments` When a path starts with `third_party/java/`, try skipping past `third_party/java/` and looking for a nested source root (`java`, `javatests`, `src`, `testsrc`) before falling back to `third_party/java/` as the root. PiperOrigin-RevId: 999987683 Change-Id: I4f251857af862cafd90a4641a12c015266ec335d --- java/common/rules/java_helper.bzl | 10 +++ test/java/common/rules/BUILD | 3 + test/java/common/rules/java_helper_tests.bzl | 76 ++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 test/java/common/rules/java_helper_tests.bzl diff --git a/java/common/rules/java_helper.bzl b/java/common/rules/java_helper.bzl index ee274ade..412292c7 100644 --- a/java/common/rules/java_helper.bzl +++ b/java/common/rules/java_helper.bzl @@ -22,6 +22,16 @@ load("//java/common:java_semantics.bzl", "semantics") def _java_segments(path): if path.startswith("/"): fail("path must not be absolute: '%s'" % path) + if path.startswith("third_party/java/"): + # For third_party/java, try skipping past the first two segments and looking for a nested + # source root, to relativize e.g. third_party/java/foo/java/resource into 'resource', + # not 'foo/java/resource'. + segments = _java_segments_impl(path[len("third_party/java/"):]) + if segments != None: + return segments + return _java_segments_impl(path) + +def _java_segments_impl(path): segments = path.split("/") root_idx = -1 for idx, segment in enumerate(segments): diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 44bb6c3f..b115dbb3 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -5,6 +5,7 @@ load(":common_launcher_java_binary_tests.bzl", "java_binary_launcher_tests") load(":common_launcher_java_library_tests.bzl", "java_library_launcher_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") +load(":java_helper_tests.bzl", "java_helper_test_suite") load(":java_import_tests.bzl", "java_import_tests") load(":java_launcher_tests.bzl", "java_launcher_tests") load(":java_library_tests.bzl", "java_library_tests") @@ -17,6 +18,8 @@ package(default_applicable_licenses = ["@rules_java//:license"]) deploy_archive_builder_test_suite(name = "deploy_archive_builder_tests") +java_helper_test_suite(name = "java_helper_tests") + merge_attrs_test_suite(name = "merge_attrs_tests") java_binary_tests(name = "java_binary_tests") diff --git a/test/java/common/rules/java_helper_tests.bzl b/test/java/common/rules/java_helper_tests.bzl new file mode 100644 index 00000000..5fdbbb60 --- /dev/null +++ b/test/java/common/rules/java_helper_tests.bzl @@ -0,0 +1,76 @@ +"""Tests for java_helper functions""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load( + "//java/common/rules:java_helper.bzl", + "helper", +) + +def _java_segments_test_impl(ctx): + env = unittest.begin(ctx) + + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("src/main/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("src/test/java/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("third_party/java/foo/javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("third_party/java/foo/src/main/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("third_party/java/foo/src/test/java/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["foo", "org", "foo", "Foo"], + helper.java_segments("third_party/java/foo/org/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_segments("foo/bar/Baz"), + ) + + return unittest.end(env) + +java_segments_test = unittest.make(_java_segments_test_impl) + +def java_helper_test_suite(name): + """Sets up java_helper test suite + + Args: + name: the name of the test suite target + """ + unittest.suite( + name, + java_segments_test, + ) From 67eac3e76c7c2321fb757f5751c0c4e8f573619e Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 15 Oct 2026 03:14:22 -0700 Subject: [PATCH 249/251] Simplify `android_support.bzl` This is change 1/N of dismantling `@compatibility_proxy` (ignore-relnotes) PiperOrigin-RevId: 1000011081 Change-Id: If8d7df47e7b50fd5c8e503101828f4d8d9317e8f --- java/private/BUILD | 2 +- java/private/android_support.bzl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/private/BUILD b/java/private/BUILD index 510c3010..244de292 100644 --- a/java/private/BUILD +++ b/java/private/BUILD @@ -76,7 +76,7 @@ bzl_library( name = "android_support", srcs = ["android_support.bzl"], visibility = ["//visibility:public"], - deps = ["@compatibility_proxy//:proxy_bzl"], + deps = [":internals"], ) filegroup( diff --git a/java/private/android_support.bzl b/java/private/android_support.bzl index fa80a17b..8301234d 100644 --- a/java/private/android_support.bzl +++ b/java/private/android_support.bzl @@ -13,8 +13,10 @@ # limitations under the License. """Legacy support for the android rules.""" -load("@compatibility_proxy//:proxy.bzl", "java_info_to_implicit_exportable") +load(":java_info.bzl", _java_info_to_implicit_exportable = "to_implicit_exportable") + +# copybara: android_support visibility android_support = struct( - enable_implicit_sourceless_deps_exports_compatibility = java_info_to_implicit_exportable, + enable_implicit_sourceless_deps_exports_compatibility = _java_info_to_implicit_exportable, ) From fe16ea80158507bdc04852386e0ca0a87542685d Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 16 Oct 2026 03:20:14 -0700 Subject: [PATCH 250/251] Internal change (ignore-relnotes) PiperOrigin-RevId: 1000737993 Change-Id: Ief2851871ffeb54f3b325b44b43ef2eb78e8cab7 --- java/common/rules/impl/java_helper.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 2ee5427a..5f89a8f1 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -289,7 +289,6 @@ helper = struct( check_and_get_main_class = _check_and_get_main_class, primary_class = _primary_class, test_classes = _test_classes, - test_srcs = _test_srcs, strip_extension = _strip_extension, concat = _concat, get_shared_native_deps_path = _get_shared_native_deps_path, From 500d0a792c747d050f788d1c38c3d92f175d5e93 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 17 Oct 2026 03:54:52 -0700 Subject: [PATCH 251/251] Add `java_path`, `java_root`, and `full_classname` to `java_helper` Factor `_java_segment_index` out of `_java_segments` in `java_helper.bzl` and expose `java_path`, `java_root`, and `full_classname` on `helper`. PiperOrigin-RevId: 1001414882 Change-Id: I21b207bbbb437fe411700812092106100fb69bdf --- java/common/rules/BUILD | 1 + java/common/rules/impl/java_helper.bzl | 15 +++-- java/common/rules/java_helper.bzl | 37 ++++++++++--- test/java/common/rules/java_helper_tests.bzl | 58 ++++++++++++++++++++ 4 files changed, 94 insertions(+), 17 deletions(-) diff --git a/java/common/rules/BUILD b/java/common/rules/BUILD index 4c24d073..fa181d26 100644 --- a/java/common/rules/BUILD +++ b/java/common/rules/BUILD @@ -92,6 +92,7 @@ filegroup( srcs = [ "BUILD", ":core_rules", + ":java_helper_bzl", ":java_single_jar_bzl", ":toolchain_rules", "//java/common/rules/impl:for_bazel_tests", diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 5f89a8f1..c7fb8693 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -89,14 +89,14 @@ def _check_and_get_main_class(ctx): return main_class def _canonical_class_from_target_name(ctx): - return _full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) + return _loading_phase_helper.full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) def _primary_class(ctx): if ctx.attr.srcs: main = ctx.label.name + ".java" for src in _test_srcs(ctx): if src.basename == main: - return _full_classname(_strip_extension(src)) + return _loading_phase_helper.full_classname(_strip_extension(src)) return _canonical_class_from_target_name(ctx) def _test_srcs(ctx): @@ -111,11 +111,6 @@ def _strip_extension(file): file.basename[:-(1 + len(file.extension))] if file.extension else file.basename ) -# TODO(b/465048589): once out of builtins, create a canonical implementation and remove duplicates in depot -def _full_classname(path): - java_segments = _loading_phase_helper.java_segments(path) - return ".".join(java_segments) if java_segments != None else None - def _test_classes(ctx): has_test_class = hasattr(ctx.attr, "test_class") and bool(ctx.attr.test_class) has_test_classes = hasattr(ctx.attr, "test_classes") and bool(ctx.attr.test_classes) @@ -129,7 +124,7 @@ def _test_classes(ctx): classes = [] for src in _test_srcs(ctx): if src.extension == "java": - cls = _full_classname(_strip_extension(src)) + cls = _loading_phase_helper.full_classname(_strip_extension(src)) if cls == None: return [] classes.append(cls) @@ -310,4 +305,8 @@ helper = struct( get_build_info = _get_build_info, get_relative = _loading_phase_helper.get_relative, has_target_constraints = _loading_phase_helper.has_target_constraints, + java_segments = _loading_phase_helper.java_segments, + java_path = _loading_phase_helper.java_path, + java_root = _loading_phase_helper.java_root, + full_classname = _loading_phase_helper.full_classname, ) diff --git a/java/common/rules/java_helper.bzl b/java/common/rules/java_helper.bzl index 412292c7..0c36be11 100644 --- a/java/common/rules/java_helper.bzl +++ b/java/common/rules/java_helper.bzl @@ -19,27 +19,27 @@ load("//java/common:java_semantics.bzl", "semantics") # copybara: rules_java visibility -def _java_segments(path): +def _java_segment_index(path): if path.startswith("/"): fail("path must not be absolute: '%s'" % path) + segments = path.split("/") if path.startswith("third_party/java/"): # For third_party/java, try skipping past the first two segments and looking for a nested # source root, to relativize e.g. third_party/java/foo/java/resource into 'resource', # not 'foo/java/resource'. - segments = _java_segments_impl(path[len("third_party/java/"):]) - if segments != None: - return segments - return _java_segments_impl(path) + idx = _java_segment_index_impl(segments[2:]) + if idx >= 0: + return idx + 2 + return _java_segment_index_impl(segments) -def _java_segments_impl(path): - segments = path.split("/") +def _java_segment_index_impl(segments): root_idx = -1 for idx, segment in enumerate(segments): if segment in ["java", "javatests", "src", "testsrc"]: root_idx = idx break if root_idx < 0: - return None + return -1 is_src = "src" == segments[root_idx] check_mvn_idx = root_idx if is_src else -1 if (root_idx == 0 or is_src): @@ -59,7 +59,23 @@ def _java_segments_impl(path): next = segments[check_mvn_idx + 2] if next in ["java", "resources"]: root_idx = check_mvn_idx + 2 - return segments[(root_idx + 1):] + return root_idx + +def _java_segments(path): + idx = _java_segment_index(path) + return path.split("/")[(idx + 1):] if idx >= 0 else None + +def _java_path(path): + java_segments = _java_segments(path) + return "/".join(java_segments) if java_segments != None else None + +def _java_root(path): + idx = _java_segment_index(path) + return "/".join(path.split("/")[:(idx + 1)]) if idx >= 0 else None + +def _full_classname(path): + java_segments = _java_segments(path) + return ".".join(java_segments) if java_segments != None else None def _has_target_constraints(ctx, constraints): # Constraints is a label_list. @@ -219,4 +235,7 @@ helper = struct( get_relative = _get_relative, has_target_constraints = _has_target_constraints, java_segments = _java_segments, + java_path = _java_path, + java_root = _java_root, + full_classname = _full_classname, ) diff --git a/test/java/common/rules/java_helper_tests.bzl b/test/java/common/rules/java_helper_tests.bzl index 5fdbbb60..89a44d24 100644 --- a/test/java/common/rules/java_helper_tests.bzl +++ b/test/java/common/rules/java_helper_tests.bzl @@ -60,6 +60,64 @@ def _java_segments_test_impl(ctx): helper.java_segments("foo/bar/Baz"), ) + asserts.equals( + env, + "com/google/foo/Foo", + helper.java_path("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "com/google/foo/Foo", + helper.java_path("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_path("foo/bar/Baz"), + ) + + asserts.equals( + env, + "java", + helper.java_root("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "javatests", + helper.java_root("javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + "foo/java", + helper.java_root("foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "third_party/java/foo/java", + helper.java_root("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_root("foo/bar/Baz"), + ) + + asserts.equals( + env, + "com.google.foo.Foo", + helper.full_classname("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "com.google.foo.Foo", + helper.full_classname("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.full_classname("foo/bar/Baz"), + ) + return unittest.end(env) java_segments_test = unittest.make(_java_segments_test_impl)