Skip to content

wix-playground/rules_maven_third_party

Repository files navigation

Rules Maven Third Party

Maven artifact resolver for Bazel JVM projects

Usage

See example for a complete workspace.

Running bazel run @managed_third_party//:resolve -- --resolve-locally generates pin under third_party directory. Default location can be changed with --destination command line option. DESTINATION_DIRECTORY environment variable can be used to generate pin outside the current workspace.

Pin files can be loaded with:

load("//:third_party.bzl", "managed_third_party_dependencies")

managed_third_party_dependencies()

@managed_third_party repository is configured with:

managed_third_party(
    artifacts = MANAGED_DEPS + TOOL_DEPS,
    import_external_macro_name = "import_external",
    import_external_rule_path = "@rules_maven_third_party//:import_external.bzl",
    repository_urls = REPOSITORY_URLS,
)

artifacts is a list of high level artifact definitions. Example of such list:

load("@rules_maven_third_party//rules:maven_specs.bzl", "wix")

MANAGED_DEPS = [
    wix.artifact(group = "junit", artifact = "junit", version = "4.13.2"),
]

import_external_macro_name and import_external_rule_path configure to load statement in generated pin file:

load("@rules_maven_third_party//:import_external.bzl", import_external = "import_external")

def dependencies():
    import_external(
        name = "junit_junit",
        artifact = "junit:junit:4.13.2",
        artifact_sha256 = "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3",
        srcjar_sha256 = "34181df6482d40ea4c046b063cb53c7ffae94bdf1b1d62695bdf3adf9dea7e3a",
        deps = [
            "@org_hamcrest_hamcrest_core",
        ],
    )

repository_urls allows to specify list of maven repositories to look for artifacts

wix.artifact attributes:

  • group: The Maven artifact coordinate group name (ex: "com.google.guava").
  • artifact: The Maven artifact coordinate artifact name (ex: "guava").
  • version: The Maven artifact coordinate version name (ex: "1.20.1").
  • ownership_tag: 3rd party dependency owner responsible for its maintenance. not implemented
  • packaging: The Maven artifact coordinate packaging name (ex: "jar").
  • classifier: The Maven artifact coordinate classifier name (ex: "jdk11").
  • exclusions: Artifact dependencies to be excluded from resolution closure.
  • neverlink: neverlink value to set,
  • testonly: testonly value to set. not implemented
  • tags: Target tags.
  • flatten_transitive_deps: Define all transitive deps as direct deps.
  • aliases: aliases that will point to this dep.

Known bugs, missing features

  • testonly does not work
  • sometimes after removing high level dep, third_party.bzl entry is not removed resulting in load failure

Future direction

  • minimize tool dependencies
  • add full coursier support
  • possibly rewrite the tool in Java to remove need for complex Rules Scala setup and dependencies

Maintenance

Maintainer: Vaidas Pilkauskas (@liucijus)

Original code written internally by multiple folks at Wix.com.

About

Bazel Rules to resolve Maven dependecies transitively

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 14