Fork me on GitHub
#clojure-dev
<
2024-03-21
>
jjttjj17:03:49

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]

seancorfield18:03:16

I strongly suspect that bypasses the dynamic class loader path...

seancorfield18:03:01

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))"

jjttjj18:03:03

Ah, thanks so much! That's been confusing me for months

seancorfield18:03:03

I used to use that code with a Socket REPL to enable the old tools.deps.alpha branch with add-lib 🙂

jjttjj18:03:13

Yeah I think I actually was using that your dot-clojure repo at some point 🙂

seancorfield18:03:59

and that "library" will start a REPL with a bunch of stuff from the classpath

jjttjj18:03:15

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 _))