{"id":20294179,"url":"https://github.com/grab/grab-bazel-common","last_synced_at":"2025-08-21T03:32:48.327Z","repository":{"id":37103334,"uuid":"379151712","full_name":"grab/grab-bazel-common","owner":"grab","description":"Common rules and macros for Grab's Android projects built with Bazel.","archived":false,"fork":false,"pushed_at":"2025-06-10T03:29:24.000Z","size":254976,"stargazers_count":40,"open_issues_count":11,"forks_count":16,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-10T04:28:18.714Z","etag":null,"topics":["android","android-bazel","bazel","bazel-rules","kotlin"],"latest_commit_sha":null,"homepage":"https://grab.github.io/grazel","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grab.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-22T05:26:41.000Z","updated_at":"2025-06-10T03:29:28.000Z","dependencies_parsed_at":"2023-10-20T20:04:50.328Z","dependency_job_id":"25dffea3-35b6-4a49-a701-dd6cecaf1a09","html_url":"https://github.com/grab/grab-bazel-common","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/grab/grab-bazel-common","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgrab-bazel-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgrab-bazel-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgrab-bazel-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgrab-bazel-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grab","download_url":"https://codeload.github.com/grab/grab-bazel-common/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgrab-bazel-common/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271420528,"owners_count":24756586,"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-08-21T02:00:08.990Z","response_time":74,"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":["android","android-bazel","bazel","bazel-rules","kotlin"],"created_at":"2024-11-14T15:28:08.839Z","updated_at":"2025-08-21T03:32:43.891Z","avatar_url":"https://github.com/grab.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grab Bazel Common Android\n\nCommon rules and macros for Grab's Android projects built with Bazel. This repo provides rules and macros to support some of Android Gradle\nPlugin features in Bazel.\n\nThe repo also hosts a patched Bazel Android Tools jar with fixes for build reproducibility and databinding applied.\nSee [/patches](https://github.com/grab/grab-bazel-common/tree/master/patches) for details.\n\nThe rules are used by [Grazel](https://github.com/grab/Grazel) - Gradle plugin to automate migration to Bazel.\n\n# Usage\n\nIn `WORKSPACE` file,\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\n\ngit_repository(\n    name = \"grab_bazel_common\",\n    commit = \"\u003ccommit hash\u003e\",\n    remote = \"https://github.com/grab/grab-bazel-common.git\",\n)\n\nload(\"@grab_bazel_common//rules:repositories.bzl\", \"bazel_common_dependencies\")\n\nbazel_common_dependencies()\n\nload(\"@grab_bazel_common//rules:setup.bzl\", \"bazel_common_setup\")\n\nbazel_common_setup(\n    patched_android_tools = True, # Optionally use patched android_tools jars\n    buildifier_version = \"6.3.3\", # Optionally can specify buildifier version\n)\n\nload(\"@grab_bazel_common//rules:maven.bzl\", \"pin_bazel_common_dependencies\")\n\npin_bazel_common_dependencies()\n\nload(\"@grab_bazel_common//:workspace_defs.bzl\", \"GRAB_BAZEL_COMMON_ARTIFACTS\")\n\n# Bazel common uses few artifacts under @maven repository\nmaven_install(\n    artifacts = GRAB_BAZEL_COMMON_ARTIFACTS + [\n      # Your project artifacts \n    ]\n)    \n```\n\n# Features\n\n### Build Config Fields\n\n`Build Config` support for android projects\n\n```python\nload(\"@grab_bazel_common//tools/build_config:build_config.bzl\", \"build_config\")\n\nbuild_config(\n    name = \"feature-toggle-build-config\",\n    package_name = \"com.grab.featuretoggle\",\n    strings = {\n        \"ID\": \"Hello\",\n    },\n    ints = {},\n    longs = {},\n    strings = {},\n)\n```\n\n### Res values\n\nGradle's `resValue` strings support for Android Projects\n\n```python\nload(\"@grab_bazel_common//tools/res_value:res_value.bzl\", \"res_value\")\n# Usage of defined resValues\nandroid_library(\n    resource_files = [\n        ...\n    ] + res_value(\n        name = \"app-res-value\",\n        strings = {\n            \"prefix\": \"app\",\n            \"field\": \"debug\"\n        },\n    ),\n)\n```   \n\n### Databinding\n\nProvides a macro which in most cases can be used as a drop-in replacement to `kt_android_library` to enable support for Kotlin code when\nusing databinding. [Details](https://github.com/grab/grab-bazel-common/blob/documentation/tools/databinding/databinding.bzl). Worker support\nfor some of the internal actions can be enabled by `build --strategy=DatabindingStubs=worker`.\n\n```python\nload(\"@grab_bazel_common//tools/databinding:databinding.bzl\", \"kt_db_android_library\")\n\nkt_db_android_library(\n    name = \"module\",\n    srcs = glob([\n        \"src/main/java/com/grab/module/**/*.kt\",\n    ]),\n    assets = glob([\n        \"src/main/assets/empty_file.txt\",\n    ]),\n    assets_dir = \"src/main/assets\",\n    custom_package = \"com.grab.module\",\n    manifest = \"src/main/AndroidManifest.xml\",\n    resource_files = glob([\n        \"src/main/res/**\",\n    ]),\n    visibility = [\n        \"//visibility:public\",\n    ],\n    deps = [\n        \"@maven//:io_reactivex_rxjava2_rxjava\",\n    ],\n)\n```\n\nThis requires the following flags in `.bazelrc` file.\n\n```python\n# Databinding flags\nbuild --experimental_android_databinding_v2\nbuild --android_databinding_use_v3_4_args\nbuild --android_databinding_use_androidx\n\n# Flags to enable latest android providers in rules\nbuild --experimental_google_legacy_api\nquery --experimental_google_legacy_api\n```\n\n### Custom Resource Sets\n\nBazel expects certain Android resource folder structure (should start with `res/`) and this can conflict with Android Gradle plugin's custom\nresource source set feature which does not have this validation. This macro helps to adapt the folder to Bazel expected structure so both\nbuild systems can function.\n\nIn Gradle, if you have:\n\n```groovy\nsourceSets {\n    debug {\n        res.srcDirs += \"src/main/res-debug\"\n    }\n}\n```\n\nthe Bazel equivalent would be:\n\n```python\nload(\"@grab_bazel_common//tools/custom_res:custom_res.bzl\", \"custom_res\")\n\nandroid_binary(\n    name = \"app\",\n    custom_package = \"com.grab.playground\",\n    manifest = \"src/main/AndroidManifest.xml\",\n    resource_files = glob([\n        \"src/main/res/**\",\n    ]) + custom_res( # Wrap the folder with custom_res macro\n        dir_name = \"res-debug\",\n        resource_files = glob([\n            \"src/main/res-debug/**\",\n        ]),\n        target = \"app\",\n    ),\n)\n```\n\n### Unit Test Macros\n\nProvides macros to simplify migrating unit tests to Bazel and ports over Android Gradle\nPlugin's [return default values](https://developer.android.com/studio/test/index.html#test_options) feature. With default values, Android\nUnit tests can be executed without [Robolectric](http://robolectric.org) by relying on mocked `android.jar` as an alternative\nto `android_local_test` in Bazel.\n\nThe below macros makes assumptions that files containing Kotlin tests are named `*Tests.kt` or `Test.kt` and class name matches the file\nname.\n\n#### Kotlin Unit tests\n\n```python\nload(\"@grab_bazel_common//rules:defs.bzl\", \"kotlin_test\")\n\nkotlin_test(\n    name = \"kotlin_test\",\n    srcs = glob([\n        \"src/test/java/**/*.kt\",\n    ]),\n    deps = [\n        \":binding-adapter-bridge\",\n        \":binding-adapter-processor\",\n        \"@maven//:org_jetbrains_kotlin_kotlin_test\",\n        \"@maven//:com_github_tschuchortdev_kotlin_compile_testing\",\n        \"@maven//:junit_junit\",\n    ],\n)\n```\n\nThis will generate a single build target for all Kotlin files and individual `*Test` targets for each `*Test`\nclass\n\n#### Android Unit tests\n\nSimilarly for android unit tests, use `android_unit_test` to build and execute tests\n\n```python\nload(\"@grab_bazel_common//rules:defs.bzl\", \"android_unit_test\")\n\nandroid_unit_test(\n    name = \"android_unit_test\",\n    srcs = glob([\n        \"src/test/java/**/*.kt\",\n    ]),\n    associates = [\n        \":grab_android_local_test_lib_kt\",\n    ],\n    deps = [\n        \"@maven//:junit_junit\",\n    ],\n)\n```\n\n# License\n\n```\nCopyright 2021 Grabtaxi Holdings PTE LTE (GRAB)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrab%2Fgrab-bazel-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrab%2Fgrab-bazel-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrab%2Fgrab-bazel-common/lists"}