Fork me on GitHub
#depstar
<
2020-09-14
>
zhuxun201:09:13

When building a uberjar using clojure -A:depstar -m hf.depstar.uberjar MyProject.jar, I get a long list of "clashing jar item" warnings like

{:warning "clashing jar item", :path "org/mozilla/javascript/ContextListener.class", :strategy :noop}
{:warning "clashing jar item", :path "org/mozilla/javascript/ContinuationPending.class", :strategy :noop}
{:warning "clashing jar item", :path "org/mozilla/javascript/DToA.class", :strategy :noop}
{:warning "clashing jar item", :path "org/mozilla/javascript/Decompiler.class", :strategy :noop}
{:warning "clashing jar item", :path "org/mozilla/javascript/DefaultErrorReporter.class", :strategy :noop}
{:warning "clashing jar item", :path "org/mozilla/javascript/DefiningClassLoader.class", :strategy :noop}
...
What do they mean and should I care? Thanks!

zhuxun201:09:46

And why are the strategies ":noop"?

seancorfield01:09:54

They're warnings, so you can ignore them. It's just saying that the file was found in multiple dependencies that you have. :noop means it didn't try to do anything. For some file type it will merge/concatenate the files.

seancorfield01:09:19

You can use the -S / --suppress-clash option to hide those messages if you want.

👍 3
seancorfield01:09:36

I'm probably going to make that the default and and an option to display them only as needed since a lot of people seem to be very concerned about "warnings" if they don't understand classpaths and dependencies can contain duplicates.

zhuxun201:09:48

Hmmm. The above command did generate a "MyProject.jar", however, trying to run it with java -jar MyProject.jar resulted in an error:

Error: Invalid or corrupt jarfile MyProject.jar

seancorfield01:09:58

You didn't specify a main class in your JAR to execute, and you didn't compile it.

seancorfield01:09:09

If you read the README, it explains the various ways to make JAR files and how you can run each one. In particular, for the command you ran

clojure -A:depstar -m hf.depstar.uberjar MyProject.jar
java -cp MyProject.jar clojure.main -m project.core

seancorfield01:09:15

I just updated the README to make it clear that folks need to read more of the information there if they want to use java -jar to run their uberjar.

zhuxun201:09:13

It seems to be working now, thanks!

zhuxun201:09:51

Yeah, a bit of heads-up will be tremendously helpful for us newbies 🙂

seancorfield01:09:22

See if the updated readme helps now.

seancorfield01:09:44

(I'm working on making the clash warnings off by default)

zhuxun201:09:59

Is there a way to manually deal with the item clashes? I just found out that another package's index.html appears in my public, which is going to create problems...

zhuxun201:09:52

@seancorfield The update is very clear and helpful. Thanks!

3
seancorfield01:09:53

Unfortunately, there are some libraries that have been incorrectly packaged -- they shouldn't contain things that would conflict with user's normal files (like public/index.html) so you should report a bug against the library that is doing that.

seancorfield01:09:22

(and this is partly why depstar has previously defaulted to providing this warning)

zhuxun201:09:34

Got it. Is there a way to find out which one is the offending package?

seancorfield02:09:09

There was a discussion about this a week or two ago in one of the channels here because some library was causing exactly that problem, with a stray index.html file 😐

zhuxun202:09:49

I mean in this case its relatively obvious once I read the index.html, but when it's not obvious is there a way to know which package it is?

seancorfield02:09:52

You can use the -v option on depstar to tell you exactly what files are being copied in and that should tell you -- it will be large output so you'll want to redirect it to a file.

zhuxun202:09:32

Got ya. Wouldn't it be more helpful if the warnings themselves can point them out? Just a thought

seancorfield02:09:05

By the time it sees a conflict, it no longer knows where the previous file came from.

seancorfield02:09:31

And conflicts are not always a problem.

seancorfield02:09:11

The real issue is that the order of things on the classpath is not always deterministic.

seancorfield02:09:50

So it's OK to have the same file present in multiple dependencies, but it's sometimes not OK to have the same filename with different contents.

seancorfield02:09:07

(and this is true of Java classpaths in general -- this isn't a Clojure issue)

zhuxun202:09:08

Got ya, so basically, if all is done correctly, namespaces should never clash unless they literally are the same thing

zhuxun202:09:25

@seancorfield But I mean, that's exactly why it would be great if the warning can point me which package it is -- so that I can know who is being naughty (even just let me know the second one would be great, which I assume depstar has the reference when the clash happens).

seancorfield02:09:27

@zhuxun2 The information about which dependency is being processed is not available by the time the warning is issued.

seancorfield02:09:53

(and it's just as likely that the one that "causes" the conflict would be seen as your code, depending on where it was in the classpath)

seancorfield02:09:01

So -v is the best way to debug that.

seancorfield02:09:16

I'll probably cut 1.1.115 tomorrow with the changes made so far. That will make it harder to detect problematic index.html files, by the way, since the warning will be off by default.

seancorfield02:09:23

(dinner time here)

seancorfield04:09:58

`seancorfield/depstar {:mvn/version "1.1.116"}` is available https://github.com/seancorfield/depstar/releases/tag/v1.1.116 -- it suppresses the clashing jar item warning by default and adds -D / --debug-clash to enable the warnings.

cap10morgan15:09:43

Getting an error with 1.1.116 (that I don't get with 1.1.104) building an uberjar w/ some exclusions on clojure 1.10.1.561: {:error "unable to copy file", :name "clojure/tools/reader/default_data_readers.clj", :exception java.lang.ClassCastException, :message nil}. I'm invoking it like this:

:main-opts ["-m" "hf.depstar.uberjar" "-X" "fluree/db/.*\\.clj[cs]?$" "target/fluree-ledger.standalone.jar" "-C" "-m" "fluree.db.server"]
I haven't been able to create a minimal reproduction scenario yet, and the project in question is private. But I thought I'd post here in case you already have a lead suspect @seancorfield. 🙂

cap10morgan15:09:19

Happy to turn all that into a GitHub issue if you'd like.

seancorfield16:09:59

@cap10morgan Sorry. Roll back to 1.1.104 and I'll fix it a.s.a.p.

cap10morgan16:09:52

No worries. And thanks!

seancorfield17:09:55

Can you share your deps.edn? I'm having a hard time reproducing the bug (although I think I know what is causing it).

seancorfield17:09:21

I think that tools.reader might be ending up on your classpath twice (but I'm not sure how).

seancorfield17:09:52

If you want to just share it privately, you can email details to <mailto:[email protected]|[email protected]>

seancorfield17:09:31

And if you could run that failing command on 1.1.116 with -D and -v options added to produce all the debug output, that would be really helpful @cap10morgan

cap10morgan17:09:07

sure I can email it to you

cap10morgan17:09:27

I'll try it again w/ -v and -D too

seancorfield17:09:28

(I think the clash strategy logic is seeing default_data_readers.clj and mistakenly treating it like data_readers.clj -- bug in my regex -- and then trying to merge it... which of course fails... but I'm not sure how you'd get tools.reader on your classpath twice 😐 )

seancorfield17:09:29

OK, yeah, it's finding default_data_readers.clj twice and trying to merge them which is the bug I thought it might be. I can't figure out why it's on the classpath twice (and, strangely, the verbose debugging output doesn't tell me so I'll need to dig into that some more and figure out what I'm not not displaying in verbose mode -- but that's a separate issue).

seancorfield17:09:27

Try 1.1.117 which I just released to Clojars.

cap10morgan18:09:52

Looks like it's fixed! Thanks!

seancorfield19:09:13

OK, seancorfield/depstar {:mvn/version "1.1.117"} is available https://github.com/seancorfield/depstar/releases/tag/v1.1.117 -- it suppresses the clashing jar item warning by default and adds -D / --debug-clash to enable the warnings. This fixes an edge case bug in 1.1.116 to do with tools.reader as a dependency.