clojure-dev

2024-03-21T17:50:49.675569Z

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]

seancorfield 2024-03-21T18:04:16.979059Z

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

seancorfield 2024-03-21T18:07:01.712359Z

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

2024-03-21T18:09:03.224109Z

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

seancorfield 2024-03-21T18:10:03.668609Z

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

2024-03-21T18:11:13.041579Z

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

seancorfield 2024-03-21T18:11:29.829169Z

FWIW, I start my REPL via this: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L58-L62

👀 1
seancorfield 2024-03-21T18:11:59.160719Z

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

2024-03-21T18:16:15.411969Z

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