Fork me on GitHub
#tools-deps
<
2023-05-08
>
pauld16:05:34

I'm trying to get an uberjar via windows clojure. I am getting this issue:

Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
C:\Users\Paul Dumais\AppData\Local\Temp\uber10211030562887780850\LICENSE (Access is denied)

Alex Miller (Clojure team)17:05:38

when compile-clj fails, it should leave the temp directory there for debugging

Alex Miller (Clojure team)17:05:56

does that file exist? if so, can you read it?

pauld17:05:30

That directory "uber..." does not exist.

pauld17:05:48

oops one sec.

pauld17:05:02

yeah that directory does not exist.

pauld17:05:26

no directories starting with that name exist.

pauld17:05:03

I switched to :use-cp-file :always

pauld17:05:32

Sorry 🌄 ":never"

Alex Miller (Clojure team)17:05:07

oh sorry, that's the uber building dir, my previous comment was re compile-clj so is not relevant

Alex Miller (Clojure team)17:05:29

you mentioned modifying the options of compile-clj, but you should be modifying the options of uber to affect behavior

pauld17:05:37

ok tried that with same result:

(defn uber [_]
  (b/copy-dir {:src-dirs ["src"]
               :target-dir class-dir})
  (b/compile-clj {:basis basis
                  :use-cp-file :never
                  :src-dirs ["src"]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :exclude [#"(?i)^META-INF/LICENSE/.*"
                     #"^LICENSE/.*"]
           :basis basis
           ...

pauld17:05:06

I solved the issue by adding ".*LICENSE.*" to :exclude in above.

borkdude17:05:45

This may be caused by Windows \\ instead of / Perhaps tools build can normalize/unixify the paths before comparing or so

borkdude17:05:37

@U0FH1UL84 So it worked with :use-cp-file :never?

pauld17:05:37

The space in my user name (home dir) was probably an issue.

pauld17:05:58

Not sure why it worked since I was likely over the 8k character limit.

borkdude17:05:11

spaces in paths should be handled imo

pauld17:05:39

could be a problem with scoop clojure via bash.

pauld17:05:00

windows git bash

borkdude17:05:17

ok, maybe also try in cmd.exe and pwsh.exe then

pauld17:05:49

ok will try

pauld17:05:48

No, problem exists in powershell too.

borkdude17:05:46

Can you re-define what "the problem" is since that information is in #clj-on-windows in a thread over there, which was a different problem than the original post of this one

borkdude17:05:17

Or start a new thread over here about that one

pauld17:05:37

Sure I'll post here again to make it clear.

pauld16:05:25

I tried adding this to options of compile-clj:

:exclude [#"(?i)^META-INF/LICENSE/.*"
                            #"^LICENSE/.*"]

pauld17:05:45

Hi folks, I just wanted to repost this issue and solution here just in case it is helpful to others. I was having an issue with compile-clj failing:

λ clj -T:build uber
Error: Could not find or load main class Dumais\AppData\Local\Temp\compile-clj5675381223217921312\compile-clj;target.classes;src;C:\Users\Paul
Caused by: java.lang.ClassNotFoundException: Dumais\AppData\Local\Temp\compile-clj5675381223217921312\compile-clj;target/classes;src;C:\Users\Paul
Execution error (ExceptionInfo) at clojure.tools.build.tasks.compile-clj/compile-clj (compile_clj.clj:114).
Clojure compilation failed, working dir preserved: C:\Users\Paul Dumais\AppData\Local\Temp\compile-clj5675381223217921312

Full report at:
C:\Users\Paul Dumais\AppData\Local\Temp\clojure-12040712073046716600.edn
It looked like it was not dealing with the space correctly in my user name (home directory). Changing the :mvn/local-repo to outside that directory with a short non-space name did not help. I solved the issue by adding :use-cp-file :never to the build-clj options map.

seancorfield17:05:14

I suspect there are quite a few tools out there that will fail on directory paths that contain spaces. I've seen a lot of people recommend to have user names without spaces on Windows because of that (`Program Files` can also be problematic if folks install non-native-Windows tooling there).

pauld18:05:13

I'm using the clojure installed by scoop on windows.

pauld17:05:00

I'm using the clojure installed by scoop on windows.

borkdude17:05:42

Let's use a thread for multiple messages about the same problem

vemv20:05:25

my tools.build uberjarring script looks approximately like this: (b/compile-clj {:bindings {#'clojure.core/*assert* false}}) ...yet I still see assertions enabled in production. What are some possible reasons?

vemv20:05:29

Maybe the main (that with :gen-class) namespace isn't currently requireing the ns that shows this behavior? Although I'm using :src-dirs so it should compile everything

Alex Miller (Clojure team)20:05:01

do you have a user.clj?

hiredman20:05:47

have you looked in the output jar to see if the namespace you want to be compiled without assertions is present in the output?

👀 2
Alex Miller (Clojure team)20:05:07

off-hand, don't know. you can fork tools.build, add any print debugging you need, and point to the fork via either :local/root or to a commit sha in your fork, if that helps

👍 2
hiredman20:05:56

the aot classes for the namespace are not present in the output, then when you load the code later it will be compiled then with whatever flags that are set then

seancorfield20:05:48

I'm always surprised when I see folks turning assert off in production... Don't you want your app to "fail fast" rather than potentially continue on with bad data and cause havoc? I've always preferred to keep assert ON in production for that reason...

vemv20:05:37

I've shared this link a few times over the years :) https://en.wikipedia.org/wiki/Design_by_contract#Performance_implications The liberating thing about disabling it is that you can go as creative and heavy-handed as desired with assertions, without worrying about performance. It also helps drawing a clear line between assertionerror and ex-info (things that aren't dev sanity checks should be the latter). Particularly when assertionerror does not inherit from Exception

vemv20:05:40

Back to the topic, the expected .classis there and (print *assert*) during compile-time printed false, as expected Will investigate some other day

hiredman02:05:12

And how do you know asserts are being triggered(

hiredman02:05:11

Gotta go put kids to bed, but wild guess you are seeing spec asserts fail, and if I recall spec asserts don't respect assert

Alex Miller (Clojure team)02:05:40

correct, they have their own assertion flags

vemv09:05:07

> And how do you know asserts are being triggered a vanilla assert was. for completeness, I ended up using the same solution I've used in past production deployments. It should be redundant given the build.clj, but this double setup leaves me more assured.

(ns my.app.launcher
  "Please don't add any requires here."
  (:gen-class))

(defn -main [& args]
  (binding [*assert* false] ;; Bind *assert* before performing any requires
    (let [f @(requiring-resolve ')]
      (apply f args))))
(sadly I don't feel with the bandwidth for a full-blown investigation)