Skip to content

Commit 0c65082

Browse files
cushoncopybara-github
authored andcommitted
Allow Bazel's own build to use Java 11 language features
Fixes #14592 PiperOrigin-RevId: 422562457
1 parent 98e80e1 commit 0c65082

File tree

7 files changed

+70
-10
lines changed
  • src
    • java_tools/buildjar/java/com/google/devtools/build/buildjar
    • test/java/com/google/devtools/build/android/desugar
    • tools/android/java/com/google/devtools/build/android
  • third_party/ijar/test

7 files changed

+70
-10
lines changed

.bazelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ build:bzlmod --experimental_enable_bzlmod
3535
build:bzlmod --crosstool_top=@rules_cc.0.0.1.cc_configure.local_config_cc//:toolchain
3636
build:bzlmod --xcode_version_config=@rules_cc.0.0.1.cc_configure.local_config_xcode//:host_xcodes
3737

38+
# Enable Java 11 language features (https://github.com/bazelbuild/bazel/issues/14592)
39+
# Toolchain resolution configuration for Bazel >= 5
40+
build --java_language_version=11
41+
build --tool_java_language_version=11
42+
# Legacy configuration for Bazel <= 4
43+
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
44+
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
45+
3846
# User-specific .bazelrc
3947
try-import user.bazelrc

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BUILD

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ java_library(
5252
["javac/*.java"],
5353
exclude = JAVAC_OPTIONS_SRCS + JAVAC_TEST_SRCS,
5454
),
55+
javacopts = [
56+
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
57+
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
58+
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
59+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
60+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
61+
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
62+
],
5563
deps = [
5664
":invalid_command_line_exception",
5765
":javac_options",
@@ -60,7 +68,6 @@ java_library(
6068
"//third_party:auto_value",
6169
"//third_party:guava",
6270
"//third_party:jsr305",
63-
"//third_party/java/jdk/langtools:javac",
6471
"//third_party/protobuf:protobuf_java",
6572
],
6673
)
@@ -212,6 +219,11 @@ bootstrap_java_binary(
212219
java_test(
213220
name = "BootClassPathCachingFileManagerTest",
214221
srcs = ["javac/BootClassPathCachingFileManagerTest.java"],
222+
javacopts = [
223+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
224+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
225+
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
226+
],
215227
deps = [
216228
":javac",
217229
"//third_party:guava",

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BUILD

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@ package(default_visibility = ["//src/java_tools/buildjar:buildjar_package_group"
99
java_library(
1010
name = "plugins",
1111
srcs = ["BlazeJavaCompilerPlugin.java"],
12+
javacopts = [
13+
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
14+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
15+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
16+
],
1217
deps = [
1318
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:invalid_command_line_exception",
1419
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics",
1520
"//third_party:guava",
16-
"//third_party/java/jdk/langtools:javac",
1721
],
1822
)
1923

2024
java_library(
2125
name = "dependency",
2226
srcs = glob(["dependency/*.java"]),
27+
javacopts = [
28+
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
29+
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
30+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
31+
"--add-exports=jdk.compiler/com.sun.tools.javac.resources=ALL-UNNAMED",
32+
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
33+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
34+
],
2335
deps = [
2436
":plugins",
2537
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:JarOwner",
@@ -28,31 +40,39 @@ java_library(
2840
"//third_party:auto_value",
2941
"//third_party:guava",
3042
"//third_party:tomcat_annotations_api",
31-
"//third_party/java/jdk/langtools:javac",
3243
],
3344
)
3445

3546
java_library(
3647
name = "errorprone",
3748
srcs = glob(["errorprone/*.java"]),
49+
javacopts = [
50+
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
51+
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
52+
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
53+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
54+
],
3855
deps = [
3956
":plugins",
4057
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:invalid_command_line_exception",
4158
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics",
4259
"//third_party:error_prone",
4360
"//third_party:guava",
44-
"//third_party/java/jdk/langtools:javac",
4561
],
4662
)
4763

4864
java_library(
4965
name = "processing",
5066
srcs = glob(["processing/*.java"]),
67+
javacopts = [
68+
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
69+
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
70+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
71+
],
5172
deps = [
5273
":plugins",
5374
"//src/main/protobuf:java_compilation_java_proto",
5475
"//third_party:guava",
55-
"//third_party/java/jdk/langtools:javac",
5676
],
5777
)
5878

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ package(default_visibility = ["//visibility:public"])
55
java_library(
66
name = "statistics",
77
srcs = ["BlazeJavacStatistics.java"],
8+
javacopts = [
9+
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
10+
],
811
deps = [
912
"//third_party:auto_value",
1013
"//third_party:caffeine",
1114
"//third_party:guava",
12-
"//third_party/java/jdk/langtools:javac",
1315
],
1416
)
1517

src/test/java/com/google/devtools/build/android/desugar/BUILD

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ java_test(
320320
srcs = [
321321
"DesugarCoreLibraryFunctionalTest.java",
322322
],
323+
javacopts = ["-source 8 -target 8"],
323324
jvm_flags = [
324325
# TODO (b/72181101): -Xbootclasspath/p is removed in JDK 9.
325326
"-XX:+IgnoreUnrecognizedVMOptions",
@@ -693,7 +694,10 @@ sh_test(
693694
java_library(
694695
name = "testdata",
695696
srcs = glob(["testdata/*.java"]),
696-
javacopts = ["-Xep:SelfAssignment:OFF"],
697+
javacopts = [
698+
"-Xep:SelfAssignment:OFF",
699+
"-source 8 -target 8",
700+
],
697701
resources = ["testdata/testresource.txt"],
698702
deps = [
699703
":separate",
@@ -707,7 +711,10 @@ java_library(
707711
"testdata/*.java",
708712
"testdata/java8/**/*.java",
709713
]),
710-
javacopts = ["-Xep:SelfAssignment:OFF"],
714+
javacopts = [
715+
"-Xep:SelfAssignment:OFF",
716+
"-source 8 -target 8",
717+
],
711718
resources = ["testdata/testresource.txt"],
712719
deps = [
713720
":separate",
@@ -721,6 +728,7 @@ java_library(
721728
srcs = glob([
722729
"testdata/core_library/**/*.java",
723730
]),
731+
javacopts = ["-source 8 -target 8"],
724732
resources = ["testdata/testresource.txt"],
725733
deps = [
726734
"//third_party:error_prone",
@@ -741,7 +749,10 @@ java_library(
741749
java_library(
742750
name = "testdata_like_in_android_studio",
743751
srcs = glob(["testdata/*.java"]),
744-
javacopts = ["-Xep:SelfAssignment:OFF"],
752+
javacopts = [
753+
"-Xep:SelfAssignment:OFF",
754+
"-source 8 -target 8",
755+
],
745756
resources = ["testdata/testresource.txt"],
746757
deps = [
747758
":libseparate.jar", # puts full Jar instead of header Jar on the classpath
@@ -755,7 +766,10 @@ java_library(
755766
"testdata/*.java",
756767
"testdata/java8/**/*.java",
757768
]),
758-
javacopts = ["-Xep:SelfAssignment:OFF"],
769+
javacopts = [
770+
"-Xep:SelfAssignment:OFF",
771+
"-source 8 -target 8",
772+
],
759773
resources = ["testdata/testresource.txt"],
760774
deps = [
761775
":libseparate.jar", # puts full Jar instead of header Jar on the classpath

src/tools/android/java/com/google/devtools/build/android/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ java_library(
6464
],
6565
exclude = ["DependencyInfo.java"],
6666
),
67+
javacopts = [
68+
"--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED",
69+
],
6770
exports = [
6871
# Separated out to avoid a dependency cycle with resources/, but it logically belongs here.
6972
":dependency_info",

third_party/ijar/test/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ genrule(
209209
java_library(
210210
name = "local_and_anonymous_lib",
211211
srcs = ["LocalAndAnonymous.java"],
212+
javacopts = ["-source 8 -target 8"],
212213
)
213214

214215
genrule(

0 commit comments

Comments
 (0)