Bazel: New and Noteworthy

David Ostrovsky

Gerrit User Conference

Palo Alto, 2018

Outline

Gerrit project from build perspective

Gerrit development environment

$ bazel run polygerrit-ui:devserver

Major dependencies

Bazel migration in 2016

Gerrit build with Bazel

./imgs/bazel-choose-two.png

Gerit build evolution

Early days of Bazel: no cache support

./imgs/i-am-compiling.png

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 (https://gerrit-ci.gerritforge.com)

Bazel Team CI for Gerrit project: https://buildkite.com:

Outline: Gerrit build improvements

ElasticSearch integration with Jest library

./imgs/es_jest_client.png

Replace Jest client with ES Low Level REST client

./imgs/es_low_level_client.png

What about integration tests after removal of ES from Gerrit?

./imgs/testcontainers.png

TestContainers Library:

Use TestContainers for ElasticSearch integration tests

./imgs/es_testcontainers-docker_tests.png

Plugin integration with TestContainers

Example: kafka-event plugin integration tests without TestContainers

$ bin/zookeeper-server-start.sh config/zookeeper.properties
$ bin/kafka-server-start.sh config/server.properties
$ 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 \
   :release

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 \
    :release

JVM Container option is needed to support recent Java versions

[container]
  javaOptions = --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED

Java 11 support for JGit project

maven_jar(
    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