Skip to content

Load external dependency for foreign project without control of WORKSPACE file content #2224

@davido

Description

@davido

Gerrit Code Review project exposes plugin API and hundreds of plugins exist in the wild. Two build modes are supported:

  • Standalone plugin build mode
  • In Gerrit tree plugin build mode

Standalone plugin build mode:

Plugin project controls the content of WORKSPACE file and can add there plugin owns dependency. During build Gerrit Plugin API + plugin own dependency are downloaded from the Central and plugin artifact is created.

In Gerrit tree plugin build mode:

To short circuit the publishing of Gerrit plugin API to Central (or even to local Maven repository, in ~/.m2 directory) with this mode the plugin directory is linked to Gerrit tree under plugins/<plugin-name> and built with:

  bazel build plugins/<plugin-name>

Working example:

This works unless plugins have their own dependencies, in which case, there is no way to load them, untill WORKSPACE in Gerrit project is patched.

Example:

that depends on third party library scribe, that is loaded through plugin own WORKSPACE file:

maven_jar(
    name = "scribe_artifact",
    artifact = "org.scribe:scribe:1.3.7",
    sha1 = "583921bed46635d9f529ef5f14f7c9e83367bc6e",
)

bind(
    name = "scribe",
    actual = "@scribe_artifact//jar",
)

and added as a dependency to the plugin artifact:

gerrit_plugin(
    name = "gerrit-oauth-provider",
    srcs = glob(["src/main/java/**/*.java"]),
    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",
    ],
    resources = glob(["src/main/resources/**/*"]),
    deps = [
        "//external:scribe",
    ],
)

So in the Gerrit tree build mode, gerrit own WORKSPACE file doesn't contain this dependency and thus Gerrit tree build mode cannot be supported for all Gerrit plugins that require third party dependencies (without temporarily patching Gerrit WORKSPACE file).

FWIW: It worked as expected with Buck, by just adding the third party dependency in place (in BUCK file), see: https://github.com/davido/gerrit-oauth-provider/blob/stable-2.10/BUCK for the whole truth:

include_defs('//bucklets/gerrit_plugin.bucklet')
include_defs('//bucklets/maven_jar.bucklet')
[...]
maven_jar(
  name = 'scribe',
  id = 'org.scribe:scribe:1.3.7',
  sha1 = '583921bed46635d9f529ef5f14f7c9e83367bc6e',
  license = 'scribe',
  local_license = True,
)
[...]
gerrit_plugin(
  name = 'gerrit-oauth-provider',
  [...]
  deps = [
    ':scribe'
  ],
  [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: feature request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions