-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I make fat jars with scala_binary? #1673
Comments
If you just want a fat jar, Bazel tends to call those "deploy jars", I believe
If you have a target like
you should be able to get the deploy jar by doing
If you don't want to use a fat jar (they have some minor drawbacks, mainly relating to deduplication and JPMS modules), an alternative is to write an aspect to walk through the deps recursively. This can be used to collect all the jars so you can dump them in a directory in the container. |
Thanks a ton @srdo! I've bridged the gap left after there being no
This doesn't happen with the slim jar, but it receives absolutely everything in the Is there something that I'm missing? I've tried asking around and there's as many opinions as people I've asked:
Another solution I saw flying around was to force initialization of this class:
I'm sorry but I'm not a Scala developer and I'm just utterly lost and confused at this point due to choice fatigue :( |
I can't say for sure, but my guess would be that the fat jar is messing up the log4jplugins.dat file. Each log4j-related jar contains one of those files, and they need to be merged in order to work. Likely the fat jar is just keeping one and discarding the others (this is the "deduplication" drawback to fat jars I mentioned above). I see someone else had an issue with this here bazelbuild/bazel#22581. So maybe using a rules_java including that change will fix it. Fat jars have enough downsides that I don't use them. If upgrading rules_java doesn't fix it for you, I'll see if we can share the aspect for collecting jars transitively we use internally. It's a fairly simple bit of code. |
Oh dear... you've got it. There are 2 different
I shall try upgrading rules_java as per your recommendation. It's currently sitting at 5.0.0 |
The upgrade has not succeeded thus far: bazelbuild/rules_java#256 |
Here's the rule we use for collecting jars (I misremembered, it's not an aspect)
The way you'd use it is something like
where
Note that this is a bit quick and dirty, and it has one slightly awkward constraint: You can't have two jars with the same name in your dependencies. This is something you could probably solve if you need to. |
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:
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!
The text was updated successfully, but these errors were encountered: