Gerrit plug-in development case


Recently, I took on the task of Gerrit plug-in development for some special reasons. I originally wanted to find a ready-made demo from the Internet for reference. As a result, I spent most of the time stunned and didn't find a relevant plug-in case. The relevant domestic blogs either stayed in Gerrit's construction tutorial or in the instructions for use. To sum up, they stayed in the stage of use, There are few self-made wheels, but the official reference documents have been found through google. There is a long way to go in the development of basic construction tools in China. Here is a summary of my process of developing Gerrit plug-in.

gerrit plug-in development process

1. Generate the basic development environment of the project with maven tools

2. According to whether the tools to be developed are strongly coupled with gerrit, choose extension development or plug-in development

3. Set up your own local Gerrit server (most of this information on the Internet, search by yourself)

4. First, implement a basic component on the Gerrit page

5. Further development according to their own needs

topMenu function implemented in pure java

1. The first step is to define and implement the top menu class


import java.util.List;

public class HelloTopMenu implements TopMenu {
    private final List<MenuEntry> menuEntries;

    public HelloTopMenu(@PluginName String pluginName) {
        String baseUrl = "/plugins/" + pluginName + "/";
        List<MenuItem> menuItems = Lists.newArrayListWithCapacity(2);
        menuItems.add(new MenuItem("Greeting", "#/x/" + pluginName + "/", ""));
        menuItems.add(new MenuItem("Documentation", baseUrl));
        menuEntries = Lists.newArrayListWithCapacity(2);
        menuEntries.add(new MenuEntry("MITEXTEDIT", menuItems));
                new MenuEntry(
                                new MenuItem("Browse Repositories", ""))));

    public List<MenuEntry> getEntries() {
        return menuEntries;

2. The second step is to bind the implementation class in the first step to the Module class


class Module extends AbstractModule {
  protected void configure() {
    //DynamicSet.bind(binder(), ProjectWebLink.class).to(HelloWeblink.class);
    DynamicSet.bind(binder(), TopMenu.class).to(HelloTopMenu.class);

3. The third step is in POM XML

<project xmlns=""



<!--              <Gerrit-SshModule>com.googlesource.gerrit.plugins.testplugin.SshModule</Gerrit-SshModule>-->
<!--              <Gerrit-HttpModule>com.googlesource.gerrit.plugins.testplugin.HttpModule</Gerrit-HttpModule>-->

              <Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>

              <Implementation-Title>${Gerrit-ApiType} ${project.artifactId}</Implementation-Title>




Pure front-end implementation of Gerrit page button jump function

There are many realizable official components provided in the official document of gerrit. Here we provide the idea of front-end implementation to realize the basic components.

 * @Desc Gerrit Plug in development
 * @Auth CoderString

class SomeCiModule extends Polymer.Element {
    static get is() {
        return "some-ci-module";

    static get properties() {
        return {
            realPath: String,

    static get template() {
        return Polymer.html`
         Online editing: <a href$="[[realPath]]">MiText</a>

    connectedCallback() {
        var url= window.location.href;
        var prefix = "https://xxx/flaskcode/gerrit?url=";
        var path = prefix + url;
        this.realPath = `${path}`;

customElements.define(, SomeCiModule);
Gerrit.install(plugin => {
    plugin.registerCustomComponent('change-view-integration', 'some-ci-module');

Reference documents

Keywords: git

Added by jeremy0 on Wed, 09 Feb 2022 01:11:42 +0200