UncleBob
UncleBob

Reputation: 1391

Clojure repl - how can I insure that :reload-all does indeed reload all required namespaces?

There is an odd and very annoying, not to say often time-consuming, behaviour in the lein REPL.

Namely, if I use :reload-all with a namespace, and a namespace required by it has an error, the repl doesn't tell me a thing about it. It just takes the last valid build of said namespace and doesn't inform me that it did so.

Obviously, in most situations this is extremely unsatisfactory. Because I wouldn't use :reload-all if none of the required namespaces had changed, and if they did and contain an error, I would very much like to know about it, and not suddenly wonder why the code I'm executing in the REPL seems to do something completely different than the code I'm having on my screen.

Is there a way to force this behavior?

Upvotes: 4

Views: 1106

Answers (1)

OlegTheCat
OlegTheCat

Reputation: 4513

tools.namespace library may help you.

There are known issues with reloading code via (require ... :reload) or (require ... :reload-all). Therefore, instead of require, try using clojure.tools.namespace/refresh:

user> (clojure.tools.namespace.repl/refresh)

It will scan your project for files/namespaces that have changed and will reload them and their dependencies in correct order.

refresh will report about errors in dependent namespaces during reload.

Also, read about requirements for your code to use this library and potential issues.

Upvotes: 5

Related Questions