{"id":13450894,"url":"https://github.com/pubref/rules_maven","last_synced_at":"2025-09-04T16:50:16.598Z","repository":{"id":95014862,"uuid":"75999290","full_name":"pubref/rules_maven","owner":"pubref","description":"Transitive maven dependencies with Bazel.","archived":false,"fork":false,"pushed_at":"2019-04-13T20:03:08.000Z","size":60,"stargazers_count":33,"open_issues_count":5,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-09T17:06:17.333Z","etag":null,"topics":["bazel","gradle","java","maven","transitive-closure"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pubref.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-09T03:44:54.000Z","updated_at":"2024-05-07T18:39:52.000Z","dependencies_parsed_at":"2023-03-30T18:25:19.421Z","dependency_job_id":null,"html_url":"https://github.com/pubref/rules_maven","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pubref/rules_maven","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_maven","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_maven/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_maven/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_maven/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pubref","download_url":"https://codeload.github.com/pubref/rules_maven/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_maven/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273641545,"owners_count":25142245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","gradle","java","maven","transitive-closure"],"created_at":"2024-07-31T07:00:39.930Z","updated_at":"2025-09-04T16:50:16.572Z","avatar_url":"https://github.com/pubref.png","language":"Python","readme":"# `rules_maven` [![Build Status](https://travis-ci.org/pubref/rules_maven.svg?branch=master)](https://travis-ci.org/pubref/rules_maven)\n\n\u003ctable\u003e\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"https://github.com/bazelbuild.png\" height=\"120\"/\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"https://github.com/gradle.png\" height=\"120\"/\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003eRules\u003c/td\u003e\n\u003ctd\u003eMaven\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\n[Bazel](https://bazel.build) rules for working with transitive maven dependencies.\n\n\u003e The word 'maven' here refers to 'maven artifacts', not the tool 'mvn'.  This\n\u003e repo utilizes gradle to assist with transitive dependency management, hence\n\u003e the logo reference. \n\n## Rules\n\n|               Name   |  Description |\n| -------------------: | :----------- |\n| [maven_repositories](#maven_repositories) |  Load dependencies for this repo. |\n| [maven_repository](#maven_repository) | Declare an external workspace that defines transitive dependencies for a set of maven artifacts. |\n\n**Status**: experimental, but actively in use for other internal projects.\n\n## Usage\n\n### 1. Add rules_maven to your WORKSPACE\n\n```python\ngit_repository(\n  name = \"org_pubref_rules_maven\",\n  remote = \"https://github.com/pubref/rules_maven\",\n  commit = HEAD, # replace with latest version\n)\n\nload(\"@org_pubref_rules_maven//maven:rules.bzl\", \"maven_repositories\")\nmaven_repositories()\n```\n\n### 2a. Define an initial maven_repository rule naming the root artifact(s)\n\n```python\nload(\"@org_pubref_rules_maven//maven:rules.bzl\", \"maven_repository\")\n\nmaven_repository(\n  name = \"guice\",\n  deps = [\n    'com.google.inject:guice:4.1.0',\n  ],\n)\n```\n\nGiven this initial repository rule defintion, `rules_maven` will:\n\n1. write a `build.gradle` file,\n\n1. install `gradle` as it's own internal dependency (first time only;\n   does not interfere with any other gradle you might have installed).\n\n1. call `gradle dependencies` and parse the output,\n\n1. fetch the expected sha1 values for named artifacts,\n\n1. write a `@guice//:rules.bzl` file having the requisite `maven_jar`\n   rules (organized by configuration),\n\n1. write a `@guice//:BUILD` file with the requisite `java_library`\n   that bundle/export dependencies (one per configuration).\n\n1. print out a formatted `maven_repository` *\"hermetic-form\"* rule with\n   all the transitive dependencies and their sha1 values explicitly named\n   (can be disabled via the `hermetic = False` attribute)\n\n### 2b. Copy and paste the closed-form back into your WORKSPACE.\n\n`rules_maven` will regurgitate a so-called *closed-form*\n`maven_repository` rule enumerating the transitive dependencies and\ntheir sha1 values in the `transitive_deps` attribute.  Assuming you\ntrust the data, copy and paste this back into your `WORKSPACE`.\n\n```python\nmaven_repository(\n  name = 'guice',\n  deps = [\n    'com.google.inject:guice:4.1.0',\n  ],\n  transitive_deps = [\n    '0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8:aopalliance:aopalliance:1.0',\n    '6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9:com.google.guava:guava:19.0',\n    'eeb69005da379a10071aa4948c48d89250febb07:com.google.inject:guice:4.1.0',\n    '6975da39a7040257bd51d21a231b76c915872d38:javax.inject:javax.inject:1',\n  ],\n)\n```\n\nOnce the `transitive_deps` is stable (all transitive deps and their correct\nsha1 values are listed), `rules_maven` will be silent.\n\n\u003e Note: make sure you leave out the artifact ID type, `rules_maven`\n\u003e will get confused about it.  For example, don't say\n\u003e `com.google.inject:guice:jar:4.1.0` (leave out the `:jar`\n\u003e substring).\n\n### 3. Load the `@guice//:rules.bzl` file in your WORKSPACE and invoke the desired macro configuration.\n\nThe `rules.bzl` file (a generated file) contains macro definitions\nthat ultimately define `native.maven_jar` rules.  A separate macro is\ndefined for each *gradle configuration*.  The default configurations\nare: `compile`, `runtime`, `compileOnly`, `compileClasspath`,\n`testCompile`, and `testRuntime`.  (these can be customized via the\n`configurations` attribute).\n\nThe name of the macros are the gradle configuration name, prefixed\nwith the rule name.  In this case there are the following macros (and\nseveral others):\n\n* `guice_compile`: Provide compile-time dependencies.\n* `guice_runtime`: Provide runtime-time dependencies.\n* ...\n\n\n```python\nload(\"@guice//:rules.bzl\", \"guice_compile\")\nguice_compile()\n```\n\n\u003e In this case, both `_compile` and `_runtime` macros provide the same dependencies.\n\n\u003e You can inspect the contents of the generated file via:\n\n```sh\n$ cat $(bazel info output_base)/external/guice/rules.bzl\n```\n\n### 4. Depend on the java_library rule for the desired configuration.\n\n```python\njava_binary(\n  name = \"app\",\n  main_class = \"example.App\",\n  deps = [\"@guice//:compile\"],\n)\n```\n\n### Final WORKSPACE\n\nTo further illustrate steps 1-3 are all in the same file.\n\n```python\ngit_repository(\n  name = \"org_pubref_rules_maven\",\n  remote = \"https://github.com/pubref/rules_maven\",\n  commit = HEAD, # replace with latest version\n)\nload(\"@org_pubref_rules_maven//maven:rules.bzl\", \"maven_repositories\", \"maven_repository\")\nmaven_repositories()\n\n\nmaven_repository(\n  name = 'guice',\n  deps = [\n    'com.google.inject:guice:4.1.0',\n  ],\n  transitive_deps = [\n    '0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8:aopalliance:aopalliance:1.0',\n    '6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9:com.google.guava:guava:19.0',\n    'eeb69005da379a10071aa4948c48d89250febb07:com.google.inject:guice:4.1.0',\n    '6975da39a7040257bd51d21a231b76c915872d38:javax.inject:javax.inject:1',\n  ],\n)\nload(\"@guice//:rules.bzl\", \"guice_compile\")\nguice_compile()\n```\n\n\n### maven_repository attributes\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| `name` | `string` | `None` | The rule name. |\n| `deps` | `string_list` | `[]` | List of maven artifacts having the form `NAME:GROUP:VERSION` |\n| `gradle_build_file` | `label` | `None` | Use the given `build.gradle` file to name dependencies (rather than generating one based on `deps` |\n| `transitive_deps` | `string_list` | `[]` | List of maven artifacts in the transitive set reachable from `deps`.  The have the form `SHA1:NAME:GROUP:VERSION`, and are calculated by rules_maven via a generated `build.gradle` file. |\n| `exclude` | `string_list_dict` | `{}` | List of artifacts to exclude, in the form `{ 'NAME:GROUP': ['EXCLUDED_GROUP:EXCLUDED_NAME']` |\n| `force` | `string_list` | `[]` | List of artifacts to force, in the form `[ 'NAME:GROUP:VERSION']` |\n| `omit` | `string_list` | `[]` | List of patterns to skip.  The pattern must either be a substring of the coordinate  `[ 'NAME:GROUP:VERSION']` or equal to the generated workspace name. |\n| `hermetic` | `bool` | `True` | Regurgitate the rule with all transitive deps listed |\n| `repositories` | `string_list_dict` | `{}` | A mapping of artifact-id pattern to url (see below) |\n| `configurations` | `string_list` | `[\"compile\", \"default\", \"runtime\", \"compileOnly\", \"compileClasspath\"]` | List of configurations to generate a corresponding rule for. |\n| `experimental_disambiguate_maven_jar_workspace_names` | `bool` | `False` | See Note |\n\n\n\u003e `experimental_disambiguate_maven_jar_workspace_names`: This option\n\u003e changes the name of the generated workspace name for maven_jar\n\u003e rules.  For example, consider the artifact\n\u003e `com.google.guava:guava:20.0`.  The corresponding workspace name\n\u003e under default conditions is `com_google_guava_guava`.  If\n\u003e `experimental_disambiguate_maven_jar_workspace_names = True`, the\n\u003e workspace name includes the version specifier and becomes\n\u003e `com_google_guava_guava_20_0`.\n\nExample use of the `repositories` attribute:\n\n\n```python\n# Load commons-imaging from adobe nexus repository.\n# Load everything else (junit) from maven central.\nmaven_repository(\n    name = \"maven\",\n    repositories = {\n        \"https://repo.adobe.com/nexus/content/repositories/public/\": [\n            \"org.apache.commons:commons-imaging\",\n        ],\n    },\n    deps = [\n        \"junit:junit:4.12\",\n        \"org.apache.commons:commons-imaging:1.0-R1534292\",\n    ],\n)\n```\n\n# Credits\n\nThe anteater image is a reference to the O'Reilly book cover.  This image is\nactually \"Peter\", the University of California Irvine\nmascot. [**ZOT!**](http://studentaffairs.uci.edu/resources/right-facing-blk-outline.png)\n","funding_links":[],"categories":["Tooling"],"sub_categories":["Migration"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubref%2Frules_maven","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpubref%2Frules_maven","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubref%2Frules_maven/lists"}