Skip to content

Unused dependency checker exception when wrapping proto_library #1750

@kitbuilder587

Description

@kitbuilder587

I'm currently migrating our Scala 2 monorepo to Scala 3. During this process, we discovered that scala_proto_library does not support a scala_version attribute and therefore cannot be cross-compiled.

Given that our monorepo is too large to migrate to Scala 3 in a single commit, we decided to continue using Scala 2-generated protos even in Scala 3 code while the migration is running. To enable this, I wrote a wrapper around scala_proto_library:

load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", _scala_proto_library = "scala_proto_library")

def scala_proto_library(name, visibility, deps, **kwargs):
    _scala_proto_library(
        name = name + "_impl",
        visibility = visibility,
        deps = deps,
    )

    _scala_library(
        name = name,
        visibility = visibility,
        deps = [":" + name + "_impl"],
        scala_version = scala2_V,
    )

This approach works well for Scala 3 builds. However, Scala 2 builds fail with an error about an unused dependency—even though the dependency is actually used in other targets. Replacing deps with exports also doesn't help.

I created a minimal reproduction repository to demonstrate the issue.

Do you have any suggestions on how to resolve this?
Also, is there any way to enable cross-compilation support for scala_proto_library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions