rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

How do I make fat jars with scala_binary?

Open grepwood opened this issue 11 months ago • 6 comments
trafficstars

Hi everyone,

I'm in the process of migrating an in-house setup that integrates rules_scala, rules_docker, and rules_k8s into a cohesive set of rules for producing Scala-based microservices. As part of this migration, I've updated from rules_docker to rules_oci and moved to a fork of rules_k8s that works with rules_oci. However, I'm now facing a significant challenge with the final piece: creating functional Docker images for the microservices.

The documentation at rules_oci and rules_scala doesn't mention fat jars, which I believe could simplify the process. If I could produce a fat jar, it would mitigate much of the complexity—like managing dependencies for 83 separate jars—and allow me to avoid reimplementing scala_image just to make this work.

Currently, I’ve written a reimplementation of scala_image that generates two tar files:

  1. One with the anorexic jar from scala_binary.
  2. Another with a reduced set of 27 jars that were explicitly declared in the deps parameter of the anorexic JAR.

However, I suspect the remaining 66 jars are transitive dependencies of those 27, which means I'll need to recursively trace dependencies until I’ve accounted for everything. This feels like a daunting task and makes me wonder if there's a more efficient approach.

I’d really appreciate any guidance, suggestions, or examples for addressing this issue. Is there a better way to handle fat jar creation or dependency resolution in this context? Has anyone tackled something similar when using rules_oci with Scala?

Thanks in advance for any help!

grepwood avatar Dec 19 '24 11:12 grepwood