Bazel: New and Noteworthy

David Ostrovsky

Gerrit User Conference

Palo Alto, 2018


Gerrit project from build perspective

Gerrit development environment

$ bazel run polygerrit-ui:devserver

Major dependencies

Bazel migration in 2016

Gerrit build with Bazel


Gerit build evolution

Early days of Bazel: no cache support


Bazel action cache

build --disk_cache=~/.gerritcodereview/bazel-cache/cas
$ bazel build //...

Recent changes in build area

  bazel build --java_toolchain //tools:error_prone_warnings_toolchain //...

GerritForge Gerrit CI (

Bazel Team CI for Gerrit project:

Outline: Gerrit build improvements

ElasticSearch integration with Jest library


Replace Jest client with ES Low Level REST client


What about integration tests after removal of ES from Gerrit?


TestContainers Library:

Use TestContainers for ElasticSearch integration tests


Plugin integration with TestContainers

Example: kafka-event plugin integration tests without TestContainers

$ bin/ config/
$ bin/ config/
$ bazel test plugins/kafka-events:kafka_events_tests

Example: kafka-event plugin integration tests with TestContainers

Support for recent Java versions

Java 9 support

$ bazel build \
   --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 \
   --java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 \

Java 10/11 support

 $ bazel build \
    --define=ABSOLUTE_JAVABASE=/usr/lib64/jvm/java-11 \
    --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
    --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \

JVM Container option is needed to support recent Java versions

  javaOptions =

Java 11 support for JGit project

    name = "jaxb-api",
    artifact = "javax.xml.bind:jaxb-api:2.3.1",

Switching between Bazel versions I

$ grep minimum_bazel_version WORKSPACE
versions.check(minimum_bazel_version = "0.19.0")

Switching between Bazel versions II

$ git checkout v2.14.1 # corresponds to June, 2017

$ grep minimum_bazel_version WORKSPACE
<no match>

$ bazel build gerrit-server:server
ERROR: error loading package '': Encountered error while reading extension file 'closure/defs.bzl': no such package '@io_bazel_rules_closure//closure': The native http_archive rule is deprecated. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") for a drop-in replacement.
Use --incompatible_remove_native_http_archive=false to temporarily continue using the native rule.

Switching between Bazel versions III

Switching between Bazel versions IV

Thank you

David Ostrovsky

Mainatainer, Gerrit Code Review