tools.deps Injections

tl;dr A crummy hack for injecting Clojure code with tools.deps.

I was recently looking at a new project from James Reeves called hashp. It’s a utility library for producing some extra debug output, but whatever; while I may talk more about it later (it’s a nifty idea!), that’s not the focus today. Instead, its README made me curious: it provides installation instructions for both Leiningen and Boot, but nothing for a tools.deps-based project. No worries—that shouldn’t be a tremendously heavy lift.

Most of the work was already done by Mr. Reeves by putting the data_readers.clj on the source path. The only thing that’s left is to require the hashp.core namespace. In the Leiningen setup, that’s done via an :injections config option that is literally just (require 'hashp.core). Here’s one way to set up a deps.edn to do the same.

deps.edn

{:aliases
   {:hashp
    {:extra-deps {hashp {:mvn/version "0.1.0"}}
     :main-opts ["-e" "(require,'hashp.core)" "-r"]}}}

Now when you run clj -A:hashp, you’ll get a REPL that can already handle all the #p-based debugging you can throw at it.

One drawback to this approach is that, if you use it in tandem with another alias that provides its own :main-opts, only one can win. You’ll have to remember to require hashp.core, like an animal.

Questions? Comments? Contact me!

Tools Used

Clojure CLI
1.10.1.492
hashp
0.1.0