From 0232ae05e6a634d9541b87ed00d4b886610df340 Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Fri, 4 Oct 2024 21:29:28 -0700 Subject: [PATCH] Update bazel to use java 21. Required also updating `rules_java` to 7.12.1 to get access to Java 21. RELNOTES=N/A PiperOrigin-RevId: 682556297 --- .bazelrc | 8 +++---- WORKSPACE | 9 +++++-- .../processor/internal/viewmodel/BUILD | 2 +- java/dagger/hilt/processor/internal/BUILD | 2 +- .../hilt/processor/internal/root/ir/BUILD | 2 +- java/dagger/lint/BUILD | 2 +- java/dagger/spi/model/BUILD | 2 +- java/dagger/testing/compile/macros.bzl | 2 +- javatests/dagger/functional/assisted/BUILD | 2 ++ .../dagger/functional/basic/BasicTest.java | 24 +++++++++---------- javatests/dagger/functional/kotlin/BUILD | 2 +- .../dagger/functional/kotlin/processor/BUILD | 2 +- .../dagger/functional/multibindings/BUILD | 4 ++++ .../processor/internal/viewmodel/BUILD | 2 +- javatests/dagger/internal/codegen/BUILD | 2 +- test_defs.bzl | 2 +- third_party/kotlin/build_extensions/rules.bzl | 2 +- 17 files changed, 41 insertions(+), 30 deletions(-) diff --git a/.bazelrc b/.bazelrc index e02e83d0858..a3282bf8ed5 100644 --- a/.bazelrc +++ b/.bazelrc @@ -18,10 +18,10 @@ build --host_javacopt="-Xep:BetaApi:OFF" build --incompatible_sandbox_hermetic_tmp # Sets the JDK for compiling sources and executing tests. -build --java_language_version=18 -build --tool_java_language_version=18 -build --java_runtime_version=remotejdk_18 -build --tool_java_runtime_version=remotejdk_18 +build --java_language_version=21 +build --tool_java_language_version=21 +build --java_runtime_version=remotejdk_21 +build --tool_java_runtime_version=remotejdk_21 # Default source/target versions. build --javacopt="-source 8 -target 8" diff --git a/WORKSPACE b/WORKSPACE index 8ba89d24ea4..ee40fb72387 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -51,11 +51,16 @@ bazel_skylib_workspace() # Load rules_java repository ############################# +RULES_JAVA_VERSION = "7.12.1" + http_archive( name = "rules_java", - sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934", - url = "https://github.com/bazelbuild/rules_java/releases/download/5.3.5/rules_java-5.3.5.tar.gz", + urls = ["https://github.com/bazelbuild/rules_java/releases/download/%s/rules_java-%s.tar.gz" % (RULES_JAVA_VERSION, RULES_JAVA_VERSION)], + sha256 = "dfbadbb37a79eb9e1cc1e156ecb8f817edf3899b28bc02410a6c1eb88b1a6862", ) +load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains") +rules_java_dependencies() +rules_java_toolchains() ############################# # Load Android Sdk diff --git a/java/dagger/hilt/android/processor/internal/viewmodel/BUILD b/java/dagger/hilt/android/processor/internal/viewmodel/BUILD index 9e5dc9e619e..6c01d3c7b85 100644 --- a/java/dagger/hilt/android/processor/internal/viewmodel/BUILD +++ b/java/dagger/hilt/android/processor/internal/viewmodel/BUILD @@ -14,7 +14,7 @@ # Description: # ViewModelInject processor. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_plugin") package(default_visibility = ["//:src"]) diff --git a/java/dagger/hilt/processor/internal/BUILD b/java/dagger/hilt/processor/internal/BUILD index 6bcfbc978ac..cd83d83df9c 100644 --- a/java/dagger/hilt/processor/internal/BUILD +++ b/java/dagger/hilt/processor/internal/BUILD @@ -15,7 +15,7 @@ # Description: # Internal code for implementing Hilt processors. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_library") package(default_visibility = ["//:src"]) diff --git a/java/dagger/hilt/processor/internal/root/ir/BUILD b/java/dagger/hilt/processor/internal/root/ir/BUILD index 4bc1a29a2ae..33f580338e7 100644 --- a/java/dagger/hilt/processor/internal/root/ir/BUILD +++ b/java/dagger/hilt/processor/internal/root/ir/BUILD @@ -16,7 +16,7 @@ # A library containing intermediate representations of the various Hilt # aggregating annotations along with logic to process them. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") package(default_visibility = ["//:src"]) diff --git a/java/dagger/lint/BUILD b/java/dagger/lint/BUILD index 2d95571de86..1e11aa2c7bf 100644 --- a/java/dagger/lint/BUILD +++ b/java/dagger/lint/BUILD @@ -15,7 +15,7 @@ # Description: # Dagger Lint Rules -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("//:build_defs.bzl", "POM_VERSION") load("//tools/maven:maven.bzl", "gen_maven_artifact") diff --git a/java/dagger/spi/model/BUILD b/java/dagger/spi/model/BUILD index e5af4e50bd4..0dcd010d4db 100644 --- a/java/dagger/spi/model/BUILD +++ b/java/dagger/spi/model/BUILD @@ -15,7 +15,7 @@ # Description: # Dagger's core APIs exposed for plugins -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") package(default_visibility = [ # The dagger/spi should be the only direct dependent on this target. diff --git a/java/dagger/testing/compile/macros.bzl b/java/dagger/testing/compile/macros.bzl index 8283755076d..3338e8a13e6 100644 --- a/java/dagger/testing/compile/macros.bzl +++ b/java/dagger/testing/compile/macros.bzl @@ -14,7 +14,7 @@ """Macros for building compiler tests.""" load("@rules_java//java:defs.bzl", "java_binary", "java_test") -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") def compiler_test(name, size = "large", compiler_deps = None, **kwargs): """Generates a java_test that tests java compilation with the given compiler deps. diff --git a/javatests/dagger/functional/assisted/BUILD b/javatests/dagger/functional/assisted/BUILD index f954b0e0d0d..b6de05b2457 100644 --- a/javatests/dagger/functional/assisted/BUILD +++ b/javatests/dagger/functional/assisted/BUILD @@ -25,6 +25,7 @@ GenJavaTests( srcs = ["AssistedFactoryAsQualifiedBindingTest.java"], javacopts = DOCLINT_HTML_AND_SYNTAX, test_only_deps = [ + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//:dagger_with_compiler", "//third_party/java/truth", "//third_party/java/junit", @@ -114,6 +115,7 @@ GenJavaTests( srcs = ["AssistedFactoryWithMultibindingsTest.java"], javacopts = DOCLINT_HTML_AND_SYNTAX, test_only_deps = [ + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//:dagger_with_compiler", "//third_party/java/truth", "//third_party/java/junit", diff --git a/javatests/dagger/functional/basic/BasicTest.java b/javatests/dagger/functional/basic/BasicTest.java index a3e4419052a..98e07fab5c9 100644 --- a/javatests/dagger/functional/basic/BasicTest.java +++ b/javatests/dagger/functional/basic/BasicTest.java @@ -61,23 +61,23 @@ public class BasicTest { } @Theory public void boxedPrimitives(BasicComponent basicComponent) { - assertThat(basicComponent.getBoxedByte()).isEqualTo(new Byte(BOUND_BYTE)); - assertThat(basicComponent.getBoxedChar()).isEqualTo(new Character(BOUND_CHAR)); - assertThat(basicComponent.getBoxedShort()).isEqualTo(new Short(BOUND_SHORT)); - assertThat(basicComponent.getBoxedInt()).isEqualTo(new Integer(BOUND_INT)); - assertThat(basicComponent.getBoxedLong()).isEqualTo(new Long(BOUND_LONG)); - assertThat(basicComponent.getBoxedBoolean()).isEqualTo(new Boolean(BOUND_BOOLEAN)); + assertThat(basicComponent.getBoxedByte()).isEqualTo(Byte.valueOf(BOUND_BYTE)); + assertThat(basicComponent.getBoxedChar()).isEqualTo(Character.valueOf(BOUND_CHAR)); + assertThat(basicComponent.getBoxedShort()).isEqualTo(Short.valueOf(BOUND_SHORT)); + assertThat(basicComponent.getBoxedInt()).isEqualTo(Integer.valueOf(BOUND_INT)); + assertThat(basicComponent.getBoxedLong()).isEqualTo(Long.valueOf(BOUND_LONG)); + assertThat(basicComponent.getBoxedBoolean()).isEqualTo(Boolean.valueOf(BOUND_BOOLEAN)); assertThat(basicComponent.getBoxedFloat()).isEqualTo(BOUND_FLOAT); assertThat(basicComponent.getBoxedDouble()).isEqualTo(BOUND_DOUBLE); } @Theory public void boxedPrimitiveProviders(BasicComponent basicComponent) { - assertThat(basicComponent.getByteProvider().get()).isEqualTo(new Byte(BOUND_BYTE)); - assertThat(basicComponent.getCharProvider().get()).isEqualTo(new Character(BOUND_CHAR)); - assertThat(basicComponent.getShortProvider().get()).isEqualTo(new Short(BOUND_SHORT)); - assertThat(basicComponent.getIntProvider().get()).isEqualTo(new Integer(BOUND_INT)); - assertThat(basicComponent.getLongProvider().get()).isEqualTo(new Long(BOUND_LONG)); - assertThat(basicComponent.getBooleanProvider().get()).isEqualTo(new Boolean(BOUND_BOOLEAN)); + assertThat(basicComponent.getByteProvider().get()).isEqualTo(Byte.valueOf(BOUND_BYTE)); + assertThat(basicComponent.getCharProvider().get()).isEqualTo(Character.valueOf(BOUND_CHAR)); + assertThat(basicComponent.getShortProvider().get()).isEqualTo(Short.valueOf(BOUND_SHORT)); + assertThat(basicComponent.getIntProvider().get()).isEqualTo(Integer.valueOf(BOUND_INT)); + assertThat(basicComponent.getLongProvider().get()).isEqualTo(Long.valueOf(BOUND_LONG)); + assertThat(basicComponent.getBooleanProvider().get()).isEqualTo(Boolean.valueOf(BOUND_BOOLEAN)); assertThat(basicComponent.getFloatProvider().get()).isEqualTo(BOUND_FLOAT); assertThat(basicComponent.getDoubleProvider().get()).isEqualTo(BOUND_DOUBLE); } diff --git a/javatests/dagger/functional/kotlin/BUILD b/javatests/dagger/functional/kotlin/BUILD index acc0504c331..345842dcfee 100644 --- a/javatests/dagger/functional/kotlin/BUILD +++ b/javatests/dagger/functional/kotlin/BUILD @@ -15,7 +15,7 @@ # Description: # Functional test code for Dagger-Android -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_library") load("//:test_defs.bzl", "GenJavaTests") diff --git a/javatests/dagger/functional/kotlin/processor/BUILD b/javatests/dagger/functional/kotlin/processor/BUILD index f4850079422..ec147bc7274 100644 --- a/javatests/dagger/functional/kotlin/processor/BUILD +++ b/javatests/dagger/functional/kotlin/processor/BUILD @@ -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. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_plugin") package(default_visibility = ["//:src"]) diff --git a/javatests/dagger/functional/multibindings/BUILD b/javatests/dagger/functional/multibindings/BUILD index ca10daffa46..70bddd4ebc8 100644 --- a/javatests/dagger/functional/multibindings/BUILD +++ b/javatests/dagger/functional/multibindings/BUILD @@ -74,6 +74,7 @@ GenJavaTests( javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, deps = [ "//:dagger_with_compiler", + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//third_party/java/junit", "//third_party/java/truth", ], @@ -85,6 +86,7 @@ GenJavaTests( javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, deps = [ "//:dagger_with_compiler", + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//third_party/java/junit", "//third_party/java/truth", ], @@ -97,6 +99,7 @@ GenJavaTests( deps = [ "//:dagger_with_compiler", "//third_party/java/auto:value", + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//third_party/java/junit", "//third_party/java/truth", ], @@ -109,6 +112,7 @@ GenJavaTests( deps = [ "//:dagger_with_compiler", "//third_party/java/auto:value", + "//third_party/java/guava/collect", # TODO(b/): This shouldn't be needed. "//third_party/java/junit", "//third_party/java/truth", ], diff --git a/javatests/dagger/hilt/android/processor/internal/viewmodel/BUILD b/javatests/dagger/hilt/android/processor/internal/viewmodel/BUILD index 421bc3ff8f4..b127124f55b 100644 --- a/javatests/dagger/hilt/android/processor/internal/viewmodel/BUILD +++ b/javatests/dagger/hilt/android/processor/internal/viewmodel/BUILD @@ -15,7 +15,7 @@ # Description: # Tests for internal code for implementing Hilt processors. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("//java/dagger/testing/compile:macros.bzl", "kt_compiler_test") package(default_visibility = ["//:src"]) diff --git a/javatests/dagger/internal/codegen/BUILD b/javatests/dagger/internal/codegen/BUILD index 22c4daf0249..42d07a6e031 100644 --- a/javatests/dagger/internal/codegen/BUILD +++ b/javatests/dagger/internal/codegen/BUILD @@ -15,7 +15,7 @@ # Description: # Tests for the Dagger compiler/codegen -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_library") load("//:build_defs.bzl", "DOCLINT_HTML_AND_SYNTAX") load("//:test_defs.bzl", "GenJavaTests") diff --git a/test_defs.bzl b/test_defs.bzl index bc98fc0f87c..da0becdb171 100644 --- a/test_defs.bzl +++ b/test_defs.bzl @@ -17,7 +17,7 @@ load("@rules_java//java:defs.bzl", "java_library", "java_test") load("//:build_defs.bzl", "JAVA_RELEASE_MIN") load( - "@io_bazel_rules_kotlin//kotlin:kotlin.bzl", + "@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test", ) diff --git a/third_party/kotlin/build_extensions/rules.bzl b/third_party/kotlin/build_extensions/rules.bzl index f1d9b7c65dd..14aa4ef73bb 100644 --- a/third_party/kotlin/build_extensions/rules.bzl +++ b/third_party/kotlin/build_extensions/rules.bzl @@ -14,7 +14,7 @@ """Convenience wrapper for kt_android_library.""" -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", io_kt_android_library = "kt_android_library") +load("@io_bazel_rules_kotlin//kotlin:android.bzl", io_kt_android_library = "kt_android_library") def kt_android_library(**kwargs): io_kt_android_library(**kwargs)