commit b89332d7c726fcc14ab87c1bb7fda91afce43179 Author: David Ostrovsky Date: Mon Apr 27 07:06:24 2020 +0200 Prefer java language level to Java 11 per default The default commands, bazel {build,test,...} use a remote Java 11 toolchain by default. The output generated is a major=55 bytecode that won't run on Java 8. Java 8 support is deprecated, but not removed, so that Java 8 language level can still be produced by the build tool chain: $ bazel build \ --java_toolchain=//tools:error_prone_warnings_toolchain \ release Until some Gerrit stakeholders are not ready to migrate to Java 11 language level, the validations can still happen using the Java 8. Change-Id: I79434c657bd3750fd9ba4596d95e2c496fb5ed70 diff --git a/.bazelrc b/.bazelrc index bf3aa6c..9f13f70 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,7 +2,7 @@ build --workspace_status_command="python ./tools/workspace_status.py" --strategy build --repository_cache=~/.gerritcodereview/bazel-cache/repository build --action_env=PATH build --disk_cache=~/.gerritcodereview/bazel-cache/cas -build --java_toolchain //tools:error_prone_warnings_toolchain +build --java_toolchain=//tools:error_prone_warnings_toolchain_java11 # Enable strict_action_env flag to. For more information on this feature see # https://groups.google.com/forum/#!topic/bazel-discuss/_VmRfMyyHBk. diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt index ee2f4a1..086e836 100644 --- a/Documentation/dev-bazel.txt +++ b/Documentation/dev-bazel.txt @@ -18,7 +18,7 @@ should generate a .war file under `bazel-bin/gerrit.war`. To build Gerrit from source, you need: * A Linux or macOS system (Windows is not supported at this time) -* A JDK for Java 8|9|10|11|... +* A JDK for Java 8|11|... * Python 2 or 3 * link:https://github.com/nodesource/distributions/blob/master/README.md[Node.js (including npm),role=external,window=_blank] * Bower (`npm install -g bower`) @@ -54,6 +54,27 @@ To check the installed version of Java, open a terminal window and run: `java -version` +[[java-8]] +==== Java 8 support (deprecated) + +Java 8 is a legacy Java release and support for Java 8 will be discontinued +in future gerrit releases. To build Gerrit with Java 8 language level, run: + +``` + $ bazel build --java_toolchain //tools:error_prone_warnings_toolchain_java8 + :release +``` + +[[java-11]] +==== Java 11 support + +Java language level 11 is the default. To build Gerrit with Java 11 language +level, run: + +``` + $ bazel build :release +``` + [[java-13]] ==== Java 13 support @@ -101,22 +122,6 @@ EOF Now, invoking Bazel with just `bazel build :release` would include all those options. -[[java-11]] -==== Java 11 support - -Java 11 is supported through alternative java toolchain -link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option]. -To build Gerrit with Java 11, specify JDK 11 java toolchain: - -``` - $ bazel build \ - --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 \ - --javabase=@bazel_tools//tools/jdk:remote_jdk11 \ - --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 \ - --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 \ - :release -``` - === Node.js and npm packages See link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/README.md#installing-node_js-and-npm-packages[Installing Node.js and npm packages,role=external,window=_blank]. diff --git a/tools/BUILD b/tools/BUILD index 5159177..be12735 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -17,6 +17,54 @@ default_java_toolchain( visibility = ["//visibility:public"], ) +JDK11_JVM_OPTS = select({ + "@bazel_tools//src/conditions:openbsd": ["-Xbootclasspath/p:$(location @bazel_tools//tools/jdk:javac_jar)"], + "//conditions:default": [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--patch-module=java.compiler=$(location @bazel_tools//tools/jdk:java_compiler_jar)", + "--patch-module=jdk.compiler=$(location @bazel_tools//tools/jdk:jdk_compiler_jar)", + "--add-opens=java.base/java.nio=ALL-UNNAMED", + "--add-opens=java.base/java.lang=ALL-UNNAMED", + ], +}) + +default_java_toolchain( + name = "error_prone_warnings_toolchain_java11", + bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"], + forcibly_disable_header_compilation = False, + genclass = ["@bazel_tools//tools/jdk:genclass"], + header_compiler = ["@bazel_tools//tools/jdk:turbine"], + header_compiler_direct = ["@bazel_tools//tools/jdk:turbine_direct"], + ijar = ["@bazel_tools//tools/jdk:ijar"], + javabuilder = ["@bazel_tools//tools/jdk:javabuilder"], + javac = ["@bazel_tools//tools/jdk:javac_jar"], + javac_supports_workers = True, + jvm_opts = JDK11_JVM_OPTS, + misc = [ + "-XDskipDuplicateBridges=true", + "-g", + "-parameters", + ], + package_configuration = [ + ":error_prone", + ], + singlejar = ["@bazel_tools//tools/jdk:singlejar"], + source_version = "11", + target_version = "11", + tools = [ + "@bazel_tools//tools/jdk:java_compiler_jar", + "@bazel_tools//tools/jdk:jdk_compiler_jar", + ], + visibility = ["//visibility:public"], +) + # Error Prone errors enabled by default; see ../.bazelrc for how this is # enabled. This warnings list is originally based on: # https://github.com/bazelbuild/BUILD_file_generator/blob/master/tools/bazel_defs/java.bzl