Skip to content

Commit

Permalink
Bump rules_java to 7.12.2
Browse files Browse the repository at this point in the history
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 bazelbuild#1482 and bazelbuild#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 bazelbuild#1619 ("Bump to
rules_java 7.9.0 for Bazel 7 compatibility" in the message for
commit cd22d88). 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:

- bazelbuild/rules_java#214 (comment)

So this is a potentially breaking change, but in the good kind of way,
in that it requires an easy, future proof update.
  • Loading branch information
mbland committed Nov 30, 2024
1 parent 2f968fa commit 10c648f
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 48 deletions.
18 changes: 6 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ load("//scala:deps.bzl", "load_rules_dependencies")

load_rules_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()
Expand Down Expand Up @@ -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")
7 changes: 5 additions & 2 deletions jmh/jmh.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
},
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions scala/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def load_rules_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(
Expand Down
6 changes: 3 additions & 3 deletions scala/private/common_attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions scala/private/extensions/dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 = [
Expand All @@ -73,5 +67,3 @@ def dev_deps_repositories(
],
maven_servers = maven_servers,
)

remote_jdk21_repositories()
2 changes: 1 addition & 1 deletion scala/private/rule_impls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion scala/private/rules/scala_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
}
Expand Down
2 changes: 1 addition & 1 deletion scala/private/rules/scala_junit_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}),
Expand Down
2 changes: 1 addition & 1 deletion scala/scala_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 3 additions & 1 deletion scala/scalafmt/phase_scalafmt_ext.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions scala_proto/private/scala_proto_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion test/jmh/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions test/shell/test_twitter_scrooge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions test/src/main/resources/java_sources/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
2 changes: 1 addition & 1 deletion test/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion test/toolchains/jdk.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
8 changes: 6 additions & 2 deletions twitter_scrooge/twitter_scrooge.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 10c648f

Please sign in to comment.