Buck is allergic to Apache XMLBeans
When Apache XMLBeans is referenced as a prebuilt_jar, Buck complains as follows:
Multiple entries with same key: org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b and org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b
java.lang.IllegalArgumentException: Multiple entries with same key: org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b and org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b
at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:150)
at com.google.common.collect.ImmutableSortedMap.validateEntries(ImmutableSortedMap.java:300)
at com.google.common.collect.ImmutableSortedMap.fromEntries(ImmutableSortedMap.java:286)
at com.google.common.collect.ImmutableSortedMap$Builder.build(ImmutableSortedMap.java:408)
at com.facebook.buck.jvm.java.AccumulateClassNamesStep.calculateClassHashes(AccumulateClassNamesStep.java:169)
at com.facebook.buck.jvm.java.AccumulateClassNamesStep.execute(AccumulateClassNamesStep.java:84)
at com.facebook.buck.step.DefaultStepRunner.runStepForBuildTarget(DefaultStepRunner.java:63)
at com.facebook.buck.rules.CachingBuildEngine.executeCommandsNowThatDepsAreBuilt(CachingBuildEngine.java:1085)
at com.facebook.buck.rules.CachingBuildEngine.access$900(CachingBuildEngine.java:106)
at com.facebook.buck.rules.CachingBuildEngine$4.apply(CachingBuildEngine.java:457)
at com.facebook.buck.rules.CachingBuildEngine$4.apply(CachingBuildEngine.java:311)
at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:906)
at com.google.common.util.concurrent.Futures$1$1.run(Futures.java:635)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is because the xmlbeans JAR has multiple duplicate entries for the same file:
> unzip -l buck-out/gen/xmlbeans.jar | grep '/Location\.class'
251 07-23-12 15:42 org/apache/xmlbeans/xml/stream/Location.class
251 07-23-12 15:42 org/apache/xmlbeans/xml/stream/Location.class
Even though this JAR works with Java, it would be nice to write this off as 'this is a bad JAR file, because it contains multiple entries for the same class'. Unfortunately, there is another major build system that has had known issues where it can create JARs with multiple entries...
Steps to reproduce:
git clone https://gist.github.com/rhencke/61216f1778231ce6bd10 jarissue
cd jarissue
buck fetch :xmlbeans
buck build :xmlbeans
I feel the current behavior is correct, since implicitly dropping all but one of the duplicates means we'll silently pick one which might lead to unexpected behavior (e.g. what if the contents of the two dupliates are different) and requiring input JARs to not have duplicate classes should be pretty straight forward. In this case, something like https://gist.github.com/andrewjcg/9fa8bb8a1d94aa044a56 should be enough to explicitly sanitize the downloaded JAR before plugging it into the prebuilt_jar rule (I actually think zip_file should also probably error out here, but it should be straight forward to add a genrule which deletes one of the items).
Is this happening a lot? If not, I'm hoping adding a few extra rules to explicitly manage these JARs means we don't need to add handling of this into Buck.
Wow. That's a nice workaround- I will give that a shot. Thank you
It's happened to me 3 times in the course of trying to port a very old, very large legacy code base (probably 200-300 third-party JAR dependencies) to Buck as a skunkworks kind of project. So, it's not something happening all the time or severely impeding anything, but it's happened enough on the set of JARs it brought in to seem to warrant reporting it.
Perhaps this should go into a known issues / FAQ / workarounds page?
I'm certainly fine with that as a resolution. Having a workaround like this is perfect. Thank you.
We don't really have an FAQ page, but we'd take a PR to add one!
@brettwooldridge fixed this in #84 by allowing a prebuilt_jar rule to pull in duplicate classes in a JAR if those classes are duplicate but identical (as in the case of xmlbeans).
Sweet; thanks @brettwooldridge :D
@sdwilsh You're welcome.