Skip to content

Commit ac46f45

Browse files
cushoncopybara-github
authored andcommitted
Update default Java language version
Use `--java_language_version=''` to mean the toolchain-defined default version, instead of hard-coding a default value of the flag. PiperOrigin-RevId: 495444503 Change-Id: Ia120f37204c516df31f1f83b5e863e86d024169d
1 parent 1ce9e20 commit ac46f45

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

toolchains/default_java_toolchain.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
123123
singlejar = ["@remote_java_tools//:singlejar_cc_bin"],
124124
)
125125

126+
_DEFAULT_SOURCE_VERSION = "8"
127+
126128
def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs):
127129
"""Defines a remote java_toolchain with appropriate defaults for Bazel.
128130
@@ -145,9 +147,23 @@ def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION
145147
**toolchain_args
146148
)
147149
if toolchain_definition:
150+
source_version = toolchain_args["source_version"]
151+
if source_version == _DEFAULT_SOURCE_VERSION:
152+
native.config_setting(
153+
name = name + "_default_version_setting",
154+
values = {"java_language_version": ""},
155+
visibility = ["//visibility:private"],
156+
)
157+
native.toolchain(
158+
name = name + "_default_definition",
159+
toolchain_type = "@bazel_tools//tools/jdk:toolchain_type",
160+
target_settings = [name + "_default_version_setting"],
161+
toolchain = name,
162+
)
163+
148164
native.config_setting(
149165
name = name + "_version_setting",
150-
values = {"java_language_version": toolchain_args["source_version"]},
166+
values = {"java_language_version": source_version},
151167
visibility = ["//visibility:private"],
152168
)
153169
native.toolchain(

0 commit comments

Comments
 (0)