From 358b105f7459b42fcd42ce95e9db59314a252f02 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Nov 2024 17:51:27 -0500 Subject: [PATCH] Bump `rules_java` to 7.12.2 Updates almost all dependencies on `@bazel_tools//tools/jdk:` toolchain targets and `.bzl` files to corresponding targets and files in `@rules_java//toolchains:`. Part of #1482 and #1652. All dependencies on `@bazel_tools//tools/jdk:toolchain_type` remain, however, as there is not yet a corresponding target in `@rules_java//toolchains:`. Adds the `WORKSPACE` stanza recommended in the `rules_java` release notes, and removes our own calls to instantiate `rules_java` repos and to register `rules_java` toolchains. These changes are required to avoid build breakages when updating to `rules_scala` 7.10.0 and higher. All targets build and all tests pass under Bazel 6.5.0 and 7.4.1. --- I was on the right track in my analysis from #1619 ("Bump to rules_java 7.9.0 for Bazel 7 compatibility" in the message for commit cd22d8896f209c37be8622f1dcc9770c2dc18f48). However, I thought we _shouldn't_ update any targets from `@bazel_tools//tools/jdk:` to `@rules_java//toolchains:`. That's why I thought we were stuck on `rules_java` 7.9.0. However, this comment from @fmeum made me think switching to `@rules_java//toolchains:` actually is the preferred approach: - https://github.com/bazelbuild/rules_java/issues/214#issuecomment-2331630136 So this is a potentially breaking change, but in the good kind of way, in that it requires an easy, future proof update. --- WORKSPACE | 18 ++++++------------ jmh/jmh.bzl | 7 +++++-- scala/deps.bzl | 4 ++-- scala/private/common_attributes.bzl | 6 +++--- scala/private/extensions/dev_deps.bzl | 8 -------- scala/private/rule_impls.bzl | 2 +- scala/private/rules/scala_binary.bzl | 2 +- scala/private/rules/scala_junit_test.bzl | 2 +- scala/scala_import.bzl | 2 +- scala/scalafmt/phase_scalafmt_ext.bzl | 4 +++- scala_proto/private/scala_proto_aspect.bzl | 6 ++++-- test/BUILD | 6 +++--- test/jmh/BUILD | 2 +- test/shell/test_twitter_scrooge.sh | 8 ++++---- test/src/main/resources/java_sources/BUILD | 4 ++-- test/toolchains/BUILD.bazel | 2 +- test/toolchains/jdk.bzl | 5 ++++- twitter_scrooge/twitter_scrooge.bzl | 8 ++++++-- 18 files changed, 48 insertions(+), 48 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 9b938f061..4a01211b4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -5,6 +5,12 @@ load("//scala:deps.bzl", "rules_scala_dependencies") rules_scala_dependencies() +load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains") + +rules_java_dependencies() + +rules_java_toolchains() + load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() @@ -130,16 +136,4 @@ load("//scala/private/extensions:dev_deps.bzl", "dev_deps_repositories") dev_deps_repositories() -# Copied from bazel_tools/tools/jdk/remote_java_repository.bzl. -[ - register_toolchains( - "@remotejdk21_" + platform + "_toolchain_config_repo//:all", - ) - for platform in [ - "linux", - "macos", - "win", - ] -] - register_toolchains("//test/toolchains:java21_toolchain_definition") diff --git a/jmh/jmh.bzl b/jmh/jmh.bzl index 458e14674..5e5844216 100644 --- a/jmh/jmh.bzl +++ b/jmh/jmh.bzl @@ -69,7 +69,7 @@ scala_generate_benchmark = rule( ), ), "runtime_jdk": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + default = Label("@rules_java//toolchains:current_java_runtime"), providers = [java_common.JavaRuntimeInfo], ), }, @@ -90,7 +90,10 @@ def scala_benchmark_jmh(**kw): testonly = kw.get("testonly", False) scalacopts = kw.get("scalacopts", []) main_class = kw.get("main_class", "org.openjdk.jmh.Main") - runtime_jdk = kw.get("runtime_jdk", "@bazel_tools//tools/jdk:current_java_runtime") + runtime_jdk = kw.get( + "runtime_jdk", + "@rules_java//toolchains:current_java_runtime", + ) scala_library( name = lib, diff --git a/scala/deps.bzl b/scala/deps.bzl index 4809a560b..02668afd0 100644 --- a/scala/deps.bzl +++ b/scala/deps.bzl @@ -36,9 +36,9 @@ def rules_scala_dependencies(): http_archive, name = "rules_java", urls = [ - "https://github.com/bazelbuild/rules_java/releases/download/7.9.0/rules_java-7.9.0.tar.gz", + "https://github.com/bazelbuild/rules_java/releases/download/7.12.2/rules_java-7.12.2.tar.gz", ], - sha256 = "41131de4417de70b9597e6ebd515168ed0ba843a325dc54a81b92d7af9a7b3ea", + sha256 = "a9690bc00c538246880d5c83c233e4deb83fe885f54c21bb445eb8116a180b83", ) maybe( diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index 83165bf42..a71080296 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -29,7 +29,7 @@ common_attrs_for_plugin_bootstrapping = { "resource_strip_prefix": attr.string(), "resource_jars": attr.label_list(allow_files = True), "java_compile_toolchain": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_toolchain"), + default = Label("@rules_java//toolchains:current_java_toolchain"), providers = [java_common.JavaToolchainInfo], ), "scalacopts": attr.string_list(), @@ -82,10 +82,10 @@ common_attrs.update({ implicit_deps = { "_java_runtime": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + default = Label("@rules_java//toolchains:current_java_runtime"), ), "_java_host_runtime": attr.label( - default = Label("@bazel_tools//tools/jdk:current_host_java_runtime"), + default = Label("@rules_java//toolchains:current_host_java_runtime"), ), "_scalac": attr.label( executable = True, diff --git a/scala/private/extensions/dev_deps.bzl b/scala/private/extensions/dev_deps.bzl index 798d4afdc..29c4fd52c 100644 --- a/scala/private/extensions/dev_deps.bzl +++ b/scala/private/extensions/dev_deps.bzl @@ -2,10 +2,8 @@ load("//scala:scala_cross_version.bzl", "default_maven_server_urls") load("//scala:scala_maven_import_external.bzl", "java_import_external") -load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories") load("//third_party/repositories:repositories.bzl", "repositories") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@rules_java//java:repositories.bzl", "remote_jdk8_repos") _BUILD_TOOLS_RELEASE = "5.1.0" @@ -45,10 +43,6 @@ def dev_deps_repositories( testonly_ = True, ) - # We need to select based on platform when we use these - # https://github.com/bazelbuild/bazel/issues/11655 - remote_jdk8_repos() - repositories( fetch_sources = fetch_sources, for_artifact_ids = [ @@ -73,5 +67,3 @@ def dev_deps_repositories( ], maven_servers = maven_servers, ) - - remote_jdk21_repositories() diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 19a8a3ae8..c4ba81c5c 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -14,7 +14,7 @@ """Rules for supporting the Scala language.""" load("@bazel_skylib//lib:paths.bzl", "paths") -load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_toolchain") +load("@rules_java//toolchains:toolchain_utils.bzl", "find_java_toolchain") load(":common.bzl", "rlocationpath_from_rootpath", _collect_plugin_paths = "collect_plugin_paths") load(":resources.bzl", _resource_paths = "paths") diff --git a/scala/private/rules/scala_binary.bzl b/scala/private/rules/scala_binary.bzl index 33652858c..1b6b89b2c 100644 --- a/scala/private/rules/scala_binary.bzl +++ b/scala/private/rules/scala_binary.bzl @@ -58,7 +58,7 @@ _scala_binary_attrs = { "classpath_resources": attr.label_list(allow_files = True), "jvm_flags": attr.string_list(), "runtime_jdk": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + default = Label("@rules_java//toolchains:current_java_runtime"), providers = [java_common.JavaRuntimeInfo], ), } diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index 9e01df5c8..45daa490d 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -79,7 +79,7 @@ _scala_junit_test_attrs = { ), "jvm_flags": attr.string_list(), "runtime_jdk": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + default = Label("@rules_java//toolchains:current_java_runtime"), providers = [java_common.JavaRuntimeInfo], ), "env": attr.string_dict(default = {}), diff --git a/scala/scala_import.bzl b/scala/scala_import.bzl index 1fb01df8f..a92cc48d5 100644 --- a/scala/scala_import.bzl +++ b/scala/scala_import.bzl @@ -146,7 +146,7 @@ scala_import = rule( default = Label("@io_bazel_rules_scala//scala/settings:stamp_scala_import"), ), "java_compile_toolchain": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_toolchain"), + default = Label("@rules_java//toolchains:current_java_toolchain"), ), }, toolchains = ["@bazel_tools//tools/jdk:toolchain_type"], diff --git a/scala/scalafmt/phase_scalafmt_ext.bzl b/scala/scalafmt/phase_scalafmt_ext.bzl index 3ce44e151..0f32f87a8 100644 --- a/scala/scalafmt/phase_scalafmt_ext.bzl +++ b/scala/scalafmt/phase_scalafmt_ext.bzl @@ -24,7 +24,9 @@ ext_scalafmt = { executable = True, ), "_java_host_runtime": attr.label( - default = Label("@bazel_tools//tools/jdk:current_host_java_runtime"), + default = Label( + "@rules_java//toolchains:current_host_java_runtime", + ), ), "_runner": attr.label( allow_single_file = True, diff --git a/scala_proto/private/scala_proto_aspect.bzl b/scala_proto/private/scala_proto_aspect.bzl index 8784c08bd..fc4b95e6c 100644 --- a/scala_proto/private/scala_proto_aspect.bzl +++ b/scala_proto/private/scala_proto_aspect.bzl @@ -209,10 +209,12 @@ def _scala_proto_aspect_impl(target, ctx): def make_scala_proto_aspect(*extras): attrs = { "_java_toolchain": attr.label( - default = Label("@bazel_tools//tools/jdk:current_java_toolchain"), + default = Label("@rules_java//toolchains:current_java_toolchain"), ), "_java_host_runtime": attr.label( - default = Label("@bazel_tools//tools/jdk:current_host_java_runtime"), + default = Label( + "@rules_java//toolchains:current_host_java_runtime", + ), ), } return aspect( diff --git a/test/BUILD b/test/BUILD index 4c2d7a263..a055235d5 100644 --- a/test/BUILD +++ b/test/BUILD @@ -479,7 +479,7 @@ scala_binary( name = "scala_binary_jdk_11", srcs = ["ScalaBinaryJdk11.scala"], main_class = "scalarules.test.ScalaBinaryJdk11", - runtime_jdk = "@bazel_tools//tools/jdk:remote_jdk11", + runtime_jdk = "@rules_java//toolchains:remote_jdk11", ) # Make sure scala_library respects java_compile_toolchain during builds @@ -782,14 +782,14 @@ scala_library( "src/main/scala/scalarules/test/junit/runtime_platform/JunitRuntimePlatformTest.java", ], # make sure java compilation toolchain matches runtime toolchain ie --target - java_compile_toolchain = "@bazel_tools//tools/jdk:toolchain_java11", + java_compile_toolchain = "@rules_java//toolchains:toolchain_java11", deps = ["@io_bazel_rules_scala_junit_junit"], ) scala_junit_test( name = "JunitRuntimePlatform_test_runner", size = "small", - runtime_jdk = "@bazel_tools//tools/jdk:remote_jdk11", + runtime_jdk = "@rules_java//toolchains:remote_jdk11", suffixes = ["Test"], tests_from = [":JunitRuntimePlatform"], runtime_deps = [":JunitRuntimePlatform"], diff --git a/test/jmh/BUILD b/test/jmh/BUILD index 1942fbbe8..a36ca831b 100644 --- a/test/jmh/BUILD +++ b/test/jmh/BUILD @@ -63,7 +63,7 @@ scala_benchmark_jmh( scala_benchmark_jmh( name = "test_jmh_jdk11", srcs = ["TestJmhRuntimeJdk11.scala"], - runtime_jdk = "@bazel_tools//tools/jdk:remote_jdk11", + runtime_jdk = "@rules_java//toolchains:remote_jdk11", ) [sh_test( diff --git a/test/shell/test_twitter_scrooge.sh b/test/shell/test_twitter_scrooge.sh index 56345ad3b..a61e065d3 100644 --- a/test/shell/test_twitter_scrooge.sh +++ b/test/shell/test_twitter_scrooge.sh @@ -7,10 +7,10 @@ runner=$(get_test_runner "${1:-local}") scrooge_compile_with_jdk_11() { # javabase and java_toolchain parameters are deprecated and may be # removed in Bazel >= 5.0.0 - bazel build --javabase=@bazel_tools//tools/jdk:remote_jdk11 \ - --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 \ - --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 \ - --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 \ + bazel build --javabase=@rules_java//toolchains:remote_jdk11 \ + --host_javabase=@rules_java//toolchains:remote_jdk11 \ + --host_java_toolchain=@rules_java//toolchains:toolchain_java11 \ + --java_toolchain=@rules_java//toolchains:toolchain_java11 \ --javacopt='--release 11' \ --java_language_version=11 \ --tool_java_language_version=11 \ diff --git a/test/src/main/resources/java_sources/BUILD b/test/src/main/resources/java_sources/BUILD index 5cc8c9d7c..da7762317 100644 --- a/test/src/main/resources/java_sources/BUILD +++ b/test/src/main/resources/java_sources/BUILD @@ -5,11 +5,11 @@ package(default_visibility = ["//visibility:public"]) scala_library( name = "CompiledWithJava8", srcs = ["SimpleJavaSourceFileA.java"], - java_compile_toolchain = "@bazel_tools//tools/jdk:toolchain_java8", + java_compile_toolchain = "@rules_java//toolchains:toolchain_java8", ) scala_library( name = "CompiledWithJava11", srcs = ["SimpleJavaSourceFileB.java"], - java_compile_toolchain = "@bazel_tools//tools/jdk:toolchain_java11", + java_compile_toolchain = "@rules_java//toolchains:toolchain_java11", ) diff --git a/test/toolchains/BUILD.bazel b/test/toolchains/BUILD.bazel index e0a20ac38..1dbfcee8b 100644 --- a/test/toolchains/BUILD.bazel +++ b/test/toolchains/BUILD.bazel @@ -1,6 +1,6 @@ load("//scala:scala_toolchain.bzl", "scala_toolchain") load( - "@bazel_tools//tools/jdk:default_java_toolchain.bzl", + "@rules_java//toolchains:default_java_toolchain.bzl", "BASE_JDK9_JVM_OPTS", "DEFAULT_JAVACOPTS", "DEFAULT_TOOLCHAIN_CONFIGURATION", diff --git a/test/toolchains/jdk.bzl b/test/toolchains/jdk.bzl index b16c4ea4e..be4729297 100644 --- a/test/toolchains/jdk.bzl +++ b/test/toolchains/jdk.bzl @@ -1,5 +1,8 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("@bazel_tools//tools/jdk:remote_java_repository.bzl", "remote_java_repository") +load( + "@rules_java//toolchains:remote_java_repository.bzl", + "remote_java_repository", +) def remote_jdk21_repositories(): maybe( diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index 1bdef6ecd..16b1e4180 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -435,7 +435,9 @@ common_attrs = { ), ], ), - "_java_host_runtime": attr.label(default = Label("@bazel_tools//tools/jdk:current_host_java_runtime")), + "_java_host_runtime": attr.label( + default = Label("@rules_java//toolchains:current_host_java_runtime"), + ), } common_aspect_providers = [ @@ -475,7 +477,9 @@ scrooge_java_aspect = aspect( attrs = dicts.add( common_attrs, { - "_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")), + "_java_toolchain": attr.label(default = Label( + "@rules_java//toolchains:current_java_toolchain", + )), }, ), provides = [ScroogeAspectInfo],