{"id":13450903,"url":"https://github.com/stripe-archive/sbt-bazel","last_synced_at":"2025-03-23T16:32:38.546Z","repository":{"id":143013265,"uuid":"137815538","full_name":"stripe-archive/sbt-bazel","owner":"stripe-archive","description":"Easily convert SBT projects to Bazel workspaces","archived":true,"fork":false,"pushed_at":"2019-08-05T16:41:28.000Z","size":85,"stargazers_count":54,"open_issues_count":8,"forks_count":4,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-07-31T07:15:53.439Z","etag":null,"topics":["bazel","sbt","sbt-plugin","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/stripe-archive.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-18T23:03:11.000Z","updated_at":"2024-07-31T07:15:56.951Z","dependencies_parsed_at":"2023-04-27T11:01:09.592Z","dependency_job_id":null,"html_url":"https://github.com/stripe-archive/sbt-bazel","commit_stats":null,"previous_names":["stripe/sbt-bazel"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stripe-archive%2Fsbt-bazel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stripe-archive%2Fsbt-bazel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stripe-archive%2Fsbt-bazel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stripe-archive%2Fsbt-bazel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stripe-archive","download_url":"https://codeload.github.com/stripe-archive/sbt-bazel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221856521,"owners_count":16892456,"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","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","sbt","sbt-plugin","scala"],"created_at":"2024-07-31T07:00:40.023Z","updated_at":"2024-10-28T16:32:09.815Z","avatar_url":"https://github.com/stripe-archive.png","language":"Scala","funding_links":[],"categories":["Tooling"],"sub_categories":["Migration"],"readme":"# sbt-bazel\n\n[![Build Status](https://travis-ci.org/stripe/sbt-bazel.svg?branch=master)](https://travis-ci.org/stripe/sbt-bazel)\n\n**This plugin is considered experimental. Expect frequent breaking changes.**\n\nsbt-bazel is an sbt plugin that converts sbt projects to Bazel workspaces. This readme assumes you have basic knowledge of how a Bazel workspace is organized.\n\nThis plugin will generate BUILD files for each project along with a WORKSPACE files that handles importing [rules_scala](https://github.com/bazelbuild/rules_scala) and downloading binary artifacts from Maven repos.\n\n# Typical Usage\n\nThe [`readme-example`](https://github.com/stripe/sbt-bazel/tree/master/plugin/src/sbt-test/sbt-bazel/readme-example) project in the plugin's test directory is a minimal usage example. This section will walk through the settings used.\n\nFirst you must install the plugin in your project. Do this by adding the following to your project's `project/plugins.sbt`:\n\n```scala\naddSbtPlugin(\"com.stripe\" %% \"sbt-bazel\" % \"0.0.1\")\n```\n\nIn your project's [`build.sbt`](https://github.com/stripe/sbt-bazel/tree/master/plugin/src/sbt-test/sbt-bazel/readme-example/build.sbt) file, you must now set the version of `rules_scala`. This is done by setting `bazelScalaRulesVersion` to the SHA of the `rules_scala` commit you'd like to use. For example, to set the version to [0eab80ff0696d419aa54c2ab4b847ce9bdcbb379](https://github.com/bazelbuild/rules_scala/commit/0eab80ff0696d419aa54c2ab4b847ce9bdcbb379) add the following to the top of your build file:\n\n```scala\nThisBuild / bazelScalaRulesVersion := \"0eab80ff0696d419aa54c2ab4b847ce9bdcbb379\"\n```\n\nA common sbt pattern is to set up a root project that does not contain any source files itself, but is instead an aggregation all of a repo's sub-projects. This is the pattern the example project follows.\n\nIn order to generate one `WORKSPACE` file, enable workspace file generation with `bazelWorkspaceGenerate` for the root project. Because the root project is just an empty aggregation, it also makes sense to turn off `BUILD` file generation with `bazelBuildGenerate`. Putting all this together, the root target will look as follows:\n\n```scala\nlazy val root =  project.\n  in(file(\".\")).\n  aggregate(core, example).\n  settings(\n    bazelWorkspaceGenerate := true,\n    bazelBuildGenerate := false,\n  )\n```\n\nYou can now run the `bazelGenerate` task against the root project. The result will be `BUILD` files generated for all the aggregated projects. These will appear at the base directory of each of the projects. A `WORKSPACE` file will also be generated at the root directory of the root project, which will handle downloading binary dependencies and [rules_scala](https://github.com/bazelbuild/rules_scala).\n\nSee the `*.expect` files for examples of what the generated files will look like.\n\n# Overriding Behavior\n\nFor more complicated projects, you may need to customize the behavior of the plugin. Several settings are available to you.\n\n## Toggling File Generation\n\n- `bazelWorkspaceGenerate`: When set to `true`, a `WORKSPACE` file is generated for the current project at the project's base directory. Otherwise, no file is generated. As shown above, this will typically be set to `true` for the root aggregate project.\n- `bazelBuildGenerate`: When set to `false`, no `BUILD` file is generated for the current project. Otherwise, a `BUILD` file is generated for the current project at the project's base directory. As shown above, this will typically be set to `false` for the root aggregate project.\n\n## Customizing Workspace and Build File Generation\n\n- `bazelCustomWorkspace`: This allows customizing how the `WORKSPACE` file is generated using a DSL. By default, the `WORKSPACE` file is made up of two sections:\n  - A `WorkspacePrelude`, which contains the code to load and set up `rules_scala`\n  - And a `MavenBindings` section, which contains code to load and bind any dependency artifacts.\n\nSo the default setting is: `bazelCustomWorkspace := WorkspacePrelude +: MavenBindings`, where the `+:` operator concatenates sections together.\n\nThe `BazelString` operand allows you add arbitrary text to the `WORKSPACE` file. The following would completely replace the generated `WORKSPACE` contents with the string passed to `BazelString`: `bazelCustomWorkspace := BazelString(\"# Custom workspace file\")`\n\n- `bazelCustomBuild`: This allows customizing how the `BUILD` file is generated using a DSL. By default, the `WORKSPACE` file is made up of two sections:\n  - A `BuildPrelude`, which contains the code to load rules from `rules_scala`\n  - And a `BuildTargets` section, which contains the generated `scala_library` target and `scala_binary` target, if applicable.\n\nThe `+:` operator concatenates sections and `BazelString` allows you to specify arbitrary strings.\n\n## Customizing Dependency Generation\n\nThe plugin will add dependencies to targets based on sbt's `dependsOn` and `libraryDependencies` setting. If this needs to be overridden for some reason, this can be customized with the `bazelRuleDeps` setting. The default setting is `bazelRuleDeps := Deps(Compile)`, which means each target will include dependencies on any internal project dependencies and all dependencies in `Keys.externalDependencyClasspath`.\n\nEach operand of the DSL specifies a set of dependencies, and these sets can be used in an expression with the normal set operators: `+`, `-`, `∪`, and `∩`.\n\nThe operands are:\n\n- `Deps(config: Configuration)`: This denotes the set of all internal and external dependencies for a given config.\n- `ModuleDep(moduleId: ModuleID)`: This denotes the dependency referred to by the given `ModuleId`. For example, `ModuleDep(\"io.circe\" %% \"circe-parser\" % \"0.9.3\")`.\n- `StringDep(dep: String)`: This denotes the dependency referred to by the given string. For example, `StringDep(\"//core\")`.\n- `BazelDep(path: String, name: String)`: This denotes the dependency referred to by the combination of the given path and target name. For example, `BazelDep(\"//core\", \"core\")` denotes the Bazel dependency `//core:core`.\n- `EmptyDep`: This denotes the empty set.\n\nPutting this together, the following would remove the `circe-parser` 0.9.2 dependency and substitute it for version 0.9.3:\n\n```scala\nbazelRuleDeps := Deps(Compile) -\n  ModuleDep(\"io.circe\" %% \"circe-parser\" % \"0.9.2\") +\n  ModuleDep(\"io.circe\" %% \"circe-parser\" % \"0.9.3\")\n```\n\n## Customizing Maven Dependency Resolution in `WORKSPACE`\n\nYou can also customize which dependencies are loaded in the `WORKSPACE` file with `bazelMavenDeps`. The default is `bazelMavenDeps := AllExternalDeps(Compile)`\n\nThe operators and operands in the [Customizing Dependency Generation](#customizingdependencygeneration) section can be used here.\n\n## scala_rules Version\n\n- `bazelScalaRulesVersion`: Set the version of `scala_rules` to a specific SHA.\n\n# Limitations\n\nThe plugin has the following limitations:\n\n- All dependencies in the `Keys.externalDependencyClasspath` are added as compile time dependencies, even if they are only needed at runtime.\n- Any additional resolvers added to the `Resolver` setting are used as mirrors in the `WORKSPACE` file for *all* dependencies.\n- Only Maven resolvers are supported.\n\n# Contributing\n\nContributions are welcome. If you have a large contribution in mind, please open an issue to discuss the change first.\n\nTo update the test expectations:\n* Change the version in [`version.sbt`](https://github.com/stripe/sbt-bazel/tree/master/version.sbt) to end in `-SNAPSHOT`.\n* Install [nix](https://nixos.org/nix/).\n* Run `scripts/update_test_output.sh` from the project root.\n\n# Authors\n\n- [Andy Scott](https://twitter.com/andygscott)\n- [Alex Beal](https://twitter.com/beala)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstripe-archive%2Fsbt-bazel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstripe-archive%2Fsbt-bazel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstripe-archive%2Fsbt-bazel/lists"}