bazeltools / bazel_jar_jar

JarJar rules for bazel (rename packages and classes in existing jars)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runtime_deps are not supported

uajith opened this issue · comments

If we have a runtime_deps entry in the BUILD file like shown below

jar_jar(
    name = "shaded",
    input_jar = "abc.jar",
    inline_rules = [
        
    ],
    visibility = ["//visibility:public"],
    runtime_deps = [
        ":abcd",
        
    ],
)

Here, I am getting the error that

 no such attribute 'runtime_deps' in 'jar_jar' rule

When the jar_jar was part of bazel like in version, 3.7.1 this attribute was supported.

What are you trying to accomplish?

I'm not familiar with jarjar ever being a native rule in Bazel. I don't know what th API to their rule was.

If you let us know what you're trying to accomplish, I'll see if I can be of any help.

Situation

Upgrading Bazel from 3.7.1 to 6.4.0 in the monorepo codebase.

Changes in jar_jar bazel rule

While using jar_jar in Bazel 3.7.1, we were following these steps.

Updating the BUILD file

load("//skylib:jar_jar.bzl", "jar_jar")
jar_jar(
    name = "deploy",
    input_jar = ":deploy.jar",
    rules = [
        "rule com.google.gson.** jarjar.@0",
    ],
    visibility = ["//visibility:public"],
)

Now, we have upgraded Bazel to 6.4.0, and rules defined in skylib have become obsolete. So made these changes

Changes in WORKSPACE

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "com_github_johnynek_bazel_jar_jar",
    commit = "4e7bf26da8bc8c955578fd8c8a2c763757d344df", # Latest commit SHA as of 2023/10/31
    remote = "https://github.com/johnynek/bazel_jar_jar.git",
)

load(
    "@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl",
    "jar_jar_repositories",
)
jar_jar_repositories()

Changes in the BUILD file

load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl","jar_jar")
jar_jar(
    name = "deploy",
    input_jar = ":deploy.jar",
    inline_rules = [
        "rule com.google.gson.** jarjar.@0",
    ],
    visibility = ["//visibility:public"],
)

These changes fixed the issues with the building jar_jar rule in Bazel 6.4.0.

Current Issue

We have another BUILD file like this ( which was working fine in Bazel 3.7.1 )

load("//skylib:jar_jar.bzl", "jar_jar")
jar_jar(
    name = "actv",
    input_jar = ":actv.jar",
    rules = [
        "rule com.google.gson.** jarjar.@0",
        
    ],
    visibility = ["//visibility:public"],
    runtime_deps = [
        ":shaded",
          ],
)

This file I have changed to

load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl","jar_jar")
jar_jar(
    name = "actv",
    input_jar = ":actv.jar",
    inline_rules = [
        "rule com.google.gson.** jarjar.@0",
        
    ],
    visibility = ["//visibility:public"],
    runtime_deps = [
        ":shaded",
          ],
)

But the bazel build is failing since the runtime_deps is supported here.

I recommend removing the runtime_deps from this rule and working around the limitation. If needed you could do something like:

load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl","jar_jar")
jar_jar(
    name = "actv_jar_jar",
    input_jar = ":actv.jar",
    inline_rules = [
        "rule com.google.gson.** jarjar.@0",
        
    ],
    visibility = ["//visibility:public"],
    runtime_deps = [
        ":shaded",
          ],
)

java_library(
  name = "actv",
  runtime_deps = [":actv_jar_jar", ":shaded"]
)

or you can write a macro that does what you need if you need to do this in more than one place.

Wow..thanks..it worked.. I can make changes as suggested.