Building with Bazel

Jul 8 2022 · Starlark, Bazel 5.1, Visual Studo Code 1.66

Part 1: Learning Bazel

11. Add Dependencies

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 10. Understand Dependencies Next episode: 12. Write an iOS Build File
Transcript: 11. Add Dependencies

Episode 11 - Add Dependencies

In our workspace, we’re going to use maven as a way to resolve our dependencies. We’re going to use maven install to grab all the various artifacts. We simply provide the artifacts we want to get as well as the versions. In this case, will just be fetching the artifacts.


To get started, open the WORKSPACE in your editor of choice. We’re going to write the rules to create our android app. Let’s add a comment at the bottom.

# Rules for building Bullseye for Android

We’ll get started by loading the android SDK. In my case, I have the build tools installed. You can add build tools by way of the SDK manager in Android Studio.

    name = "androidsdk",
    api_level = 32,
    build_tools_version = "30.0.2"

Next, we’ll get the android_tools.

    name = "android_tools",
    sha256 = "ed5290594244c2eeab41f0104519bcef51e27c699ff4b379fcbd25215270513e",
    url = "",

Next we need to get android rules.

    name = "rules_android",
    urls = [""],
    sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
    strip_prefix = "rules_android-0.1.1",

Of course, building an android app we need to load the rules for the JVM. First, we’ll define a couple of variables.

RULES_JVM_EXTERNAL_SHA = "2393f002b0a274055a4e803801cd078df90d1a8ac9f15748d1f803b97cfcdc9c"

Next, we’ll get the actual JVM rules.

    name = "rules_jvm_external",
    strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
    url = "" % RULES_JVM_EXTERNAL_TAG,

Now that we have the JVM ready go, we need to get a reference to the maven install function. We’ll do this by way of load.

load("@rules_jvm_external//:defs.bzl", "maven_install")

At this point, we can now add all our dependencies. In the maven install function, we’ll pass in an array of artifacts.

    artifacts = [


Now we’ll list all our artifacts. There’s a lot of them.

artifacts = [

After which, we then define all the various repositories.

repositories = [

Finally, we set fetch sources to true to download the dependencies.

fetch_sources = True,

Believe it or not, we still have a little more code to write. The app is written in Kotlin so we must get ahold of the Kotlin rules.

rules_kotlin_version = "legacy-1.4.0-rc4"
rules_kotlin_sha = "9cc0e4031bcb7e8508fd9569a81e7042bbf380604a0157f796d06d511cff2769"

    name = "io_bazel_rules_kotlin",
    urls = ["" % rules_kotlin_version],
    sha256 = rules_kotlin_sha,

Finally, we need to get ahold of a few functions that need to be called. Add the following:

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

And that’s it. We have our Workspace all setup for both our monorepo. Before we can build, we actually need to write our build file which is what we’ll do in the next episode.