Fork me on GitHub
#babashka
<
2023-09-12
>
danm13:09:44

I'm trying to get babashka working in a sandbox. Specifically, I'm trying to generate an uberjar of deps to use elsewhere with bb --config bb.edn uberjar deps.jar, and I'm getting this error:

Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main
Exception in thread "main" java.io.FileNotFoundException: .clojure/.cpcache/CD493EC38DE8FD326E3BA44059ED15FB.cp (No such file or directory)
Now that's not pointing at my ~/.clojure, because that's outside the sandbox. So I've got a wrapper script for bb which sets CLJ_CONFIG to be in the current directory. I can see that directory, and there are cpcache entries in there:
ls 9/execroot/griffin/.clojure/.cpcache
97713C8154E4C4BD1CBB5856654237AD.basis
97713C8154E4C4BD1CBB5856654237AD.cp
but that... 'id', is not the same as the one referenced in the exception. So why is it generating a file with one ID in that directory, and then looking for a completely different one when it comes to run the main uberjar-generating command?

borkdude13:09:09

try -Sforce , rm -rf ~/.deps.clj ,

borkdude13:09:31

which bb version is this

borkdude13:09:42

recent bb versions should be more robust with respect to the downloaded tools jar

danm13:09:59

Aah. I was on 1.3.179. Have upgraded to 1.3.184 and have got a different error. It no longer complains about the classpath, but it still can't find clojure.main:

Clojure tools not yet in expected location: .deps.clj/clojure-tools-1.11.1.1403.jar
Downloading  to .deps.clj/clojure-tools.zip
Unzipping .deps.clj/clojure-tools.zip ...
Successfully installed clojure tools!
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main
Exception in thread "main" clojure.lang.ExceptionInfo:  babashka.process.Process@416433a5

danm13:09:37

Oh wait, I think I commented something by accident

danm13:09:56

Nope, same deal 😕

borkdude13:09:37

did you set HOME to something else perhaps?

borkdude13:09:47

I vaguely remember something with (System/getProperty "user.home") and HOME being dissimilar causing issues

danm13:09:13

As in the actual env var rather than a java property or similar? ${HOME} isn't set in the sandbox env. I've explicitly set CLJ_CONFIG and DEPS_CLJ_TOOLS_DIR to be inside the sandbox

danm13:09:26

Hmm, I can test that

borkdude13:09:29

you could try to download the deps.clj script and just execute it with bb like this:

bb -cp nil ./deps.clj -Sdeps-file bb.edn 
and then poke in the locally downloaded deps.clj script to see where something is going wrong

danm13:09:04

Hmm, I'm getting somewhere with looking at the cpcache directory. It's still referring to files in ~/.m2/repository.

danm13:09:20

So I'd need to try and get those to be saved somewhere within the sandbox too

borkdude13:09:23

what is your invocation of bb which gets you the error message?

borkdude13:09:56

I mean, if you get clojure.main not found for just bb and not invoking clojure itself, then this is a sign that something goes wrong while calculating the classpath

borkdude13:09:07

but if this is happening when doing bb clojure, it's another story

borkdude13:09:49

you can set the mvn local repo using -Sdeps '{:mvn/local-repo "/tmp"}'

danm13:09:57

bb works (a babashka repl launches) • bb clojure works (a clojure repl launches) • bb --config bb.edn uberjar deps.jar fails

borkdude13:09:39

bb --config bb.edn is already the default, so I don't understand why this fails, unless it's using an old cache. Try wiping ~/.clojure/.cpcache

borkdude13:09:13

bb --config bb.edn -Sforce ....
should also help

danm13:09:48

Hmm. With -Sdeps '{:mvn/local-repo "/tmp"}' the .cpcache/*.cp file is still referencing my home directory...

borkdude13:09:44

what does bb --version return

danm13:09:41

babashka v1.3.184

borkdude14:09:25

dunno. if you can provide a repro, happy to look further

danm14:09:10

It's definiteyl something to do with the sandboxing and the setting of those 2 vars. If don't sandbox but still have the vars, it still fails. If I don't sandbox and don't override the vars it works fine

borkdude14:09:31

if you can give me instructions of how to replicate such a sandbox e.g. using docker perhaps that would help

danm14:09:48

👍 I'll try and put something together. Thanks!

borkdude14:09:17

for now you could try to create the uberjar outside of the sandbox perhaps and then take it with your into the sandbox

danm13:09:41

(N.B. I had to run bb clojure to generate that directory and entry in the first place)