Skip to content

Commit

Permalink
Change the default java source_version / target_version to 11
Browse files Browse the repository at this point in the history
Using a language version of 8 and running with jdk21 (or later) results in:

```
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
```
PiperOrigin-RevId: 683542164
Change-Id: Icc9600af2543720ff98a9d695cdd526f59612b9c
  • Loading branch information
hvadehra authored and rules_java Copybara committed Oct 8, 2024
1 parent 708d0cc commit 87e5aac
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions toolchains/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ DEFAULT_JAVACOPTS = [
"-Xep:UseCorrectAssertInTests:OFF",
]

# If this is changed, the docs for "{,tool_}java_language_version" also
# need to be updated in the Bazel user manual
_DEFAULT_JAVA_LANGUAGE_VERSION = "11"

# Default java_toolchain parameters
_BASE_TOOLCHAIN_CONFIGURATION = dict(
forcibly_disable_header_compilation = False,
Expand All @@ -88,8 +92,8 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict(
# Code to enumerate target JVM boot classpath uses host JVM. Because
# java_runtime-s are involved, its implementation is in @bazel_tools.
bootclasspath = [Label("//toolchains:platformclasspath")],
source_version = "8",
target_version = "8",
source_version = _DEFAULT_JAVA_LANGUAGE_VERSION,
target_version = _DEFAULT_JAVA_LANGUAGE_VERSION,
reduced_classpath_incompatible_processors = [
"dagger.hilt.processor.internal.root.RootProcessor", # see b/21307381
],
Expand Down Expand Up @@ -137,10 +141,6 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
oneversion = Label("@remote_java_tools//:one_version_cc_bin"),
)

# If this is changed, the docs for "{,tool_}java_language_version" also
# need to be updated in the Bazel user manual
_DEFAULT_SOURCE_VERSION = "8"

def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs):
"""Defines a remote java_toolchain with appropriate defaults for Bazel.
Expand All @@ -164,7 +164,7 @@ def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION
)
if toolchain_definition:
source_version = toolchain_args["source_version"]
if source_version == _DEFAULT_SOURCE_VERSION:
if source_version == _DEFAULT_JAVA_LANGUAGE_VERSION:
native.config_setting(
name = name + "_default_version_setting",
values = {"java_language_version": ""},
Expand Down

0 comments on commit 87e5aac

Please sign in to comment.