rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

Expose maven_export and clean up kotlin/scala merged jars

Open sacsar opened this issue 2 years ago • 4 comments

Following up on our Slack discussion, there are a few things to do around exposing maven_export so it can be used with Scala:

  • expose maven_export via defs.bzl
  • update the jar merge logic to exclude "compiler artifacts" (I don't know what to call this) that get pulled in for Kotlin and Scala because they don't have Maven coordinates:
    • For Kotlin:@com_github_jetbrains_kotlin//:kotlin-stdlib
    • For Scala: @io_bazel_rules_scala_scala_reflect//:io_bazel_rules_scala_scala_reflect and @io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library (there may be others, but this was sufficient for my use case)

For anyone encountering the issue of standard library classes making it into the jar: add the appropriate targets to the deploy_env parameter.

I'm happy to make a PR or two for these. (My patch to expose maven_export in my project is a whopping three line diff, but a PR would need some docs too. The other is bigger, I think.)

sacsar avatar Feb 16 '23 16:02 sacsar

@sacsar, I think that what we're pretty close to being done here. As you point out, we can use the deploy_env parameter to avoid packing standard libraries. Should we consider exposing a scala_export and kt_java_export that are simply macros that add the standard libraries to a regular java_export?

shs96c avatar Mar 24 '23 11:03 shs96c

@shs96c IIRC, when I first wrote the ticket, I was concerned about the macro approach being fragile. However, it's a decent starting point and there can be a docstring to point people in the right direction in case my lists were incomplete.

One wrinkle is that there isn't currently a dependency on rules_scala -- are you okay with one being added?

I can take a crack at one or both this weekend.

sacsar avatar Mar 24 '23 18:03 sacsar

Apologies for not replying. Adding a dep on rules_scala is fine. The way we've handled this for the kotlin rules is to have a top-level kt_defs.bzl that includes the rules that depend on rules_kotlin: it's expected that users will have loaded that themselves already. A similar approach for rules_scala would work well

shs96c avatar May 11 '23 17:05 shs96c

Sounds good. I'll take a crack at it probably next week. Last I checked rules_scala isn't on bzlmod yet, so I may need help. (My attempts at converting my own project to bzlmod have not gone very well due to dependencies that aren't using it yet, even though I know it's meant to be possible.)

sacsar avatar May 12 '23 10:05 sacsar