-
Notifications
You must be signed in to change notification settings - Fork 4k
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
deploy jar silently clobbers jar resources having the same filename #7330
Comments
It looks like passing
So how about --
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
index a07d55df03..8dc91a6f83 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
@@ -211,6 +211,7 @@ public class DeployArchiveBuilder {
args.add("--compression");
}
args.add("--normalize");
+ args.add("--no-duplicates");
if (javaMainClass != null) {
args.add("--main_class", javaMainClass);
} Or is this something that should be hidden behind an |
Is there a way to construct a jar of jars instead of the way it's done now? |
We do that in our own custom starlark rule. |
@ittaiz do you use onejar or something else? |
How are others addressing this using bazel native deploy jar? |
Note for others that bump into this found hack that works but take care in using it as its a hack and depends on undocumented features of bazel, namely that if you put your files under a file that falls under a small curated list that bazel supports everything "just works" In my case if I drop my resource under |
I just ran into another issue but one I'm unable to control. with log4j 2 which Im assuming is ubiquitously used with java no log4j writes available plugins to a file called so when I build an uber jar I'm not seeing the concatenated list of plugins
this leads to runtime errors like how are others working around this with bazel? |
This log4j change which moves files to javas service loader for may help because that’s one of bazels undocumented directories that will merge resources but this change won’t land in a release until log4j3 in its release tracker https://issues.apache.org/jira/plugins/servlet/mobile#issue/LOG4J2-2621 |
Doing a bit more research on this merging this resource is a bit more than concatenating files it turns out there are several solutions for this for various build tools but surprisingly I could find none for bazel. only mvn, gradle, sbt, and leiningen communities have solutions for this https://github.com/search?q=Log4j2Plugins.dat&type= Surely there must be some cross section between production jvm users using log4j2 and bazel to build deploy jars out there |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
No help from @bazelbuild/triage on this one? Running into the exact same issue here with log4j... |
This was marked as "not stale". Should the bug be reopened? This is still a problem. |
@iancha1992 Could you reopen? I lack the permission to do so. |
@hvadehra left a related comment in third_party/java_src/jdk/openjdk21/src/src/java.base/share/classes/sun/security/x509/X509CertImpl.java I wonder if there's a way we could make the Blaze behaviour here more extensible, and allow some of this to be implemented as a plugin similar to the way gradle and maven handle it for uber jars, without adding combiners to singlejar for every kind of resource file that might need to be merged. I could imagine having |
Description of the problem / feature request:
When creating a deploy jar (
bazel build foo_deploy.jar
), if multiple constituent jars have resource files with identical names, only one appears in the deploy jar. This can catch users off guard, as their build succeeded but the bits will fail at runtime.This is likely to happen when porting a project from Maven to Bazel, where the Maven deployment consists of individually deployed jars, and the developer is experimenting with Bazel's monolithic deploy jar.
Bazel ought to at least emit a warning when one file clobbers another while assembling a deploy jar, if it doesn't terminate the build altogether.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
What operating system are you running Bazel on?
CentOS 6.6 and 7.2
macOS High Sierra
What's the output of
bazel info release
?"development version"
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.We track Bazel release tags, apply a few localizations / pending PR patches, and build from source.
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?n/a
Have you found anything relevant by searching the web?
Sort of. This bazel-discuss thread touches on detecting duplicated .class files: https://groups.google.com/forum/#!topic/bazel-discuss/aDoI3XTSyWA
Alex Humesky guided the original author to Singlejar.java, indicating this would be the place to start if interested in modifying Bazel.
Any other information, logs, or outputs that you want to share?
Singlejar has a
--warn_duplicate_resources
option which Bazel uses when creating source jars. Perhaps this flag should be passed in fromDeployArchiveBuilder.java
?The text was updated successfully, but these errors were encountered: