robolectric-bazel
4.14.1.2
published 2 months ago
15 stars
18 forks
10 watchers
public
1 assets
754,544 downloads
10 KB
Compatability level 1
stIWS66A/PvdB46y8JNboGVXQCuMgUko2eO+xzWOK3s=
Maintained byBen Lee
4.14.1.2
December 5, 2024

Bzlmod (MODULE.bazel)

If using Bazel 6, make sure you set the --enable_bzlmod flag

bazel_dep(name = "rules_robolectric", version = "4.14.1.2")

bazel_dep(name = "rules_jvm_external", version = "5.3")
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    artifacts = [
        "org.robolectric:robolectric:4.14.1",
    ],
    repositories = [
        "https://maven.google.com",
        "https://repo1.maven.org/maven2",
    ],
)
use_repo(maven, "maven")

Workspace

Add the robolectric and rules_jvm_external repositories in your WORKSPACE file:

http_archive(
    name = "robolectric",
    sha256 = "b2d2164bae80fcfbdd078eb2f0935ba06557402b8c814928d9e3bec7358e2b7b",
    strip_prefix = "robolectric-bazel-4.14.1.2",
    urls = ["https://github.com/robolectric/robolectric-bazel/releases/download/4.14.1.2/robolectric-bazel-4.14.1.2.tar.gz"],
)
http_archive(
    name = "rules_java",
    sha256 = "8475fae7a95463a4fd323a46b0f5601f89863ba019afa358cc9fa1d0e67cdd63",
    urls = [
        "https://github.com/bazelbuild/rules_java/releases/download/8.6.0/rules_java-8.6.0.tar.gz",
    ],
)

load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")

rules_java_dependencies()

# note that the following line is what is minimally required from protobuf for the java rules
# consider using the protobuf_deps() public API from @com_google_protobuf//:protobuf_deps.bzl
load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features")  # buildifier: disable=bzl-visibility

proto_bazel_features(name = "proto_bazel_features")

# register toolchains
load("@rules_java//java:repositories.bzl", "rules_java_toolchains")

rules_java_toolchains()

http_archive(
    name = "rules_python",
    sha256 = "c6fb25d0ba0246f6d5bd820dd0b2e66b339ccc510242fd4956b9a639b548d113",
    strip_prefix = "rules_python-0.37.2",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.37.2/rules_python-0.37.2.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

http_archive(
    name = "rules_jvm_external",
    sha256 = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac",
    strip_prefix = "rules_jvm_external-5.3",
    url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.3/rules_jvm_external-5.3.tar.gz",
)

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

maven_install(
    name = "maven",
    artifacts = [
        "com.google.truth:truth:1.1.3",
        "org.robolectric:robolectric:4.14.1",
    ],
    repositories = [
        "https://maven.google.com",
        "https://repo1.maven.org/maven2",
    ],
)

What's Changed

Full Changelog: https://github.com/robolectric/robolectric-bazel/compare/4.11.1.2...4.14.1.2

Deps:
Assets:

robolectric-bazel

This project provides build rules for integrating Robolectric into Bazel projects.

Releases


Installation

Follow instructions in the release notes from the release you use: https://github.com/robolectric/robolectric-bazel/releases

Usage

In your android_local_test targets in the BUILD files, depend on the Robolectric targets @maven//:org_robolectric_robolectric and @robolectric//bazel:android-all:

android_local_test(
    name = "greeter_activity_test",
    srcs = ["GreeterTest.java"],
    manifest = "TestManifest.xml",
    test_class = "com.example.bazel.GreeterTest",
    deps = [
        ":greeter_activity",
        "@maven//:org_robolectric_robolectric",
        "@robolectric//bazel:android-all",
    ],
)

Publishing Releases

A new release can be published by just pushing a tag.

Once the tag is pushed, GitHub Actions will build, test, and publish a release to both GitHub releases and the BCR.

Example:

git tag 4.11.1
git push origin 4.11.1