Skip to content

0.2.0 - Unit tests and artifact exclusions

Compare
Choose a tag to compare
@arunkumar9t2 arunkumar9t2 released this 12 Jan 04:05
· 252 commits to master since this release

Changelog

Features

  • Grazel now automatically infers dependency exclude rules declared in Gradle and maps it to rules_jvm_external equivalent. For example,

    implementation("androidx.constraintlayout:constraintlayout:2.1.1") {
        exclude group: "androidx.appcompat", module: "appcompat"
    }

    will generate the following in WORKSPACE file

    maven_install(
      artifacts = [
          ...
          maven.artifact(
              group = "androidx.constraintlayout",
              artifact = "constraintlayout",
              version = "2.1.1",
              exclusions = [
                  "androidx.appcompat:appcompat",
              ],
          ),
    )
  • Grazel can generate unit test rules from bazel-common. Only Kotlin is supported at the moment. Please read readme for more details.
    For example,

    load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test")
    
    grab_kt_jvm_test(
      name = "sample-kotlin-lib-test",
      srcs = glob([
          "src/test/java/**/*.kt",
      ]),
      associates = [
          "//sample-kotlin-lib",
      ],
      visibility = [
          "//visibility:public",
      ],
      deps = [
          "@maven//:junit_junit",
      ],
    )

    For android local unit tests, grab_android_local_test will be generated that ports AGP's returnDefaultValues feature to Bazel.

    load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test")
    
    grab_android_local_test(
      name = "grab_android_local_test",
      srcs = glob([
          "src/test/java/**/*.kt",
      ]),
      associates = [
          ":grab_android_local_test_lib_kt",
      ],
      deps = [
          "@maven//:junit_junit",
      ],
    )

    Both of the macros assumes the test files are in Kotlin, ends with *Test and file name matches the class name. Robolectric is currently not supported.

    Unit test generation is controlled by grazel.rules.test.enableTestMigration flag.

Contributors

  • Gradle 7.1.1 compatibility, thanks @msfjarvis.