Ready to re-use Bazel rules for Gerrit Code Review and other Java projects
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tools Add maven packaging Nov 21, 2016
.gitignore
BUILD
COPYING
README.md
WORKSPACE
gerrit_api.bzl initial revision Nov 19, 2016
gerrit_api_maven_local.bzl initial revision Nov 19, 2016
gerrit_api_neverlink.bzl
gerrit_gwt.bzl
gerrit_plugin.bzl

README.md

Gerrit Code Review Rules for Bazel

Overview

These build rules are used for building Gerrit Code Review plugins with Bazel. Plugins are compiled as .jar files containing plugin code and dependencies.

Setup

To be able to use the Gerrit rules, you must provide bindings for the plugin API jars. The easiest way to do so is to add the following to your WORKSPACE file, which will give you default versions for Gerrit plugin API.

git_repository(
  name = "com_github_davido_bazlets",
  remote = "https://github.com/davido/bazlets.git",
  commit = "2ede19cb2d2dd9d04bcb70ffc896439a27e5d50d",
)
load("@com_github_davido_bazlets//:gerrit_api.bzl",
     "gerrit_api")

Another option is to consume snapshot version of gerrit plugin API from local Maven repository (~/.m2). To use the snapshot version special method is provided:

load("@com_github_davido_bazlets//:gerrit_api_maven_local.bzl",
     "gerrit_api_maven_local")
gerrit_api_maven_local()

Basic Example

Suppose you have the following directory structure for a simple plugin:

[workspace]/
    WORKSPACE
    BUILD
    src/main/java/
    src/main/resources/
    [...]

To build this plugin, your BUILD can look like this:

load("@com_github_davido_bazlets//:gerrit_plugin.bzl",
     "gerrit_plugin")

gerrit_plugin(
  name = 'gerrit-oauth-provider',
  srcs = glob(['src/main/java/**/*.java']),
  resources = glob(['src/main/resources/**/*']),
  manifest_entries = [
    'Gerrit-PluginName: gerrit-oauth-provider',
    'Gerrit-HttpModule: com.googlesource.gerrit.plugins.oauth.HttpModule',
    'Gerrit-InitStep: com.googlesource.gerrit.plugins.oauth.InitOAuth',
    'Implementation-Title: Gerrit OAuth authentication provider',
    'Implementation-URL: https://github.com/davido/gerrit-oauth-provider',
  ],
  deps = [
    '//external:commons-codec-neverlink',
    '//external:scribe',
  ],
)

Now, you can build the Gerrit plugin by running bazel build <plugin>_deploy.jar.

For a real world example, see the gerrit-oauth-provider-plugin/.

gerrit_plugin

gerrit_plugin(name, srcs, resources, gwt_module, deps, manifest_entries):

Implicit output targets

  • <name>.jar: library containing built plugin (not shaded) jar
  • <name>_deploy.jar: archive containing plugin (shaded) jar.
Attributes
name Name, required

A unique name for this rule.

srcs List of labels, optional

List of .java source files that will be compiled.

resources List of labels, optional

List of resource files that will be passed on the classpath to the Java compiler.

gwt_module String, optional

Name of GWT UI module.

deps List of labels, optional

List of other java_libraries on which the plugin depends.

manifest_entries List of strings, optional

A list of lines to add to the META-INF/manifest.mf file generated for the *_deploy.jar target.