I've found that add-libs doesn't work for me if I use an alias that loads a file that starts a repl via clojure.main/repl
For example
I have an alias:
:repl2 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha7"}}
:main-opts
["-e" "(clojure.main/repl :print (requiring-resolve 'clojure.pprint/pprint))"]}
Then start via
clj -M:repl2
And run in this repl:
((requiring-resolve 'clojure.repl.deps/add-lib)
'io.github.nubank/morse {:git/tag "v2023.04.30.01" :git/sha "d99b09c"} ) ;; seems to do stuff and doesn't throw an error. but then:
(require '[dev.nu.morse :as morse])
;; Could not locate dev/nu/morse__init.class, dev/nu/morse.clj or dev/nu/morse.cljc on classpath.
Is there any way to make this work? [edit: simplified example]I strongly suspect that bypasses the dynamic class loader path...
This will make it work:
clj -M -e "(->>(Thread/currentThread)(.getContextClassLoader)(clojure.lang.DynamicClassLoader.)(.setContextClassLoader,(Thread/currentThread)))" -e "(clojure.main/repl :print (requiring-resolve 'clojure.pprint/pprint))"Ah, thanks so much! That's been confusing me for months
I used to use that code with a Socket REPL to enable the old tools.deps.alpha branch with add-lib 🙂
Yeah I think I actually was using that your dot-clojure repo at some point 🙂
FWIW, I start my REPL via this: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L58-L62
and that "library" will start a REPL with a bunch of stuff from the classpath
Cool, I'm definitely going to steal this pattern from there for some stuff
(try
(require 'jedi-time.core)
(println "Java Time is Datafiable...")
(catch Throwable _))