bazelbuild / rules_scala

Scala rules for Bazel
Apache License 2.0
360 stars 273 forks source link

Is it possible to bundle transitive JARs that are exported as part of a `scala_library` target, without going full `_deploy.jar`? #1495

Closed FrankPortman closed 7 months ago

FrankPortman commented 1 year ago

Apologies for reposting but I was getting no traction on StackOverflow after a week, and so I'm hoping for some guidance from the folks in this repository. Reposting from: https://stackoverflow.com/questions/75933481/using-rules-scala-bazel-how-to-bundle-transitive-jars-that-are-exported-as

Let's say I have a library such as:

scala_library(
    name = "my_favorite_scala_library",
    srcs = glob(["*.scala"]),
    exports = [
        "A",
        "B",
    ],
    deps = [
        "A",
        "B",
        "C",
        "D",
    ],
)

bazel build //path/to/my/library:my_favorite_scala_library builds a "skinny" JAR as expected and doesn't package in any dependencies or exports.

Building a _deploy.jar will package in all transitive dependencies.

Is there a simple way to have some middle ground where I can build a JAR that will package in only the main source AND any exports, either using the exports functionality or some other Bazel functionality that I may be overlooking? I'm open to both some custom invocation of a bazel build command or some field/functionality on the rule definitions that I may not be aware of.

liucijus commented 1 year ago

@FrankPortman I don't think there's anything like that out of the box. Maybe writign a custom phase_merge_jars can do what you want, example: https://github.com/bazelbuild/rules_scala/pull/1481