Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Clojure CLI by

Been away from clojure for a while, taking a fresh look at CLI & deps tool chain current status, direction & potential work flow(s). Previously maintained linux, macOS & MS Win / WSL2 dev envs, only looking at MS Win clojure right now.

Dev env includes GraalVM JDK 23, clojure 1.12.0, emacs 27.1 with minimal (ancient) lisp-inferior-mode clj-mode (https://github.com/mgrisius/clj-mode), and Apache ant/ivy 1.10.3 for Transitive Dependency Management (TDM), classpath & java command construction. My ‘legacy’ emacs, clojure & java code are operational again.

Using basic ‘old style’ simple.bat with (~60mb) über jar simple compatibility with emacs lisp-inferior-mode with ~1 second startup time, e.g. m-x eval-expression (run-lisp “simple.bat”):
java -cp E:\dev\projects\simple\target\0.0.1.standalone.jar clojure.main

Current goals include: convert to CLI & deps tools, among others.

Installed clj-msi (Clojure 1.12.0.1501) Clojure for Windows 25.5.3460.1501, create basic project, deps.edn etc. Can use CLI from cmd.exe or powershell.exe to execute basic actions: invoke REPL, check versions, download deps, create über jar etc. Command line stuff works good!

Not sure how best to leverage CLI & deps from a basic .bat file so that the resulting REPL is ‘project aware’, e.g. sees project deps.edn, build.clj, user.clj plus ‘tools.build’ related capabilities? So far, subtle differences between CLI interactive and basic .bat cmd.exe or powershell.exe results.

As the tools.build Guide states: “We want to write this program with our favorite programming language, Clojure, and tools.build is a library of functions commonly needed for builds that can be connected together in flexible ways. Writing a build program does take a bit more code than other declarative approaches, but can be easily extended or customized far into the future, creating a build that grows with your project.”

I prefer writing clojure code over complex cross platform compatible (shell) scripts, workarounds or hacks. So, I think I want full CLI functionality to use from the REPL to avoid incidental complexity, e.g. ‘very complicated’ problems discussed in Clojure CLI Reference in ‘Quoting keys and values’ related to platform specific issues wrt cmd.exe or powershell.exe concerns. Overall goal: avoid ‘technical debt’ from ANY platform specific minutiae for ANY shell, e.g. bash/tcsh, cmd.exe, powershell.exe, or even any new emacs lisp to focus solely on investment in purest clojure value chain possible.

BTW: happily seems like there’s ‘critical mass’ for a (fairly complete) ‘dynamic’ clojure dev env with tools akin to early lisp machine (lispm) (e.g. Symbolics) ‘procedural’ style defsystem.

Re-read clojure doc a few times, no mention on how a REPL is or s/b connected (‘in-process’) in a single VM with access to a ‘project’ with ‘tools.build’ and related features enabled? Or how to switch ‘build context’ to another ‘project’. Looked at monorepo / Polylith type subprojects that use ‘with-project-root’. Might be a good fit for a ‘mega project’ but doesn’t seem like a good fit (at least to me) for disparate, scattered or loosely coupled projects. Could keep a list of target project dirs and ‘map’ specific build tool process using ‘with-project-root’?

Also mentioned in tools.build Guide: ‘Parametrized builds’ that s/b easy to use from CLI and via programmatic use to generate :dev :test :debug :deploy :install :prod :maintenance or :whatever actions or artifacts are required in conjunction with a ‘clj -T:build action-name’ approach. Seems very reasonable, if there was a repeatable initial setup or process to make project deps.edn etc. & tools.build aware at a REPL.

To summarize, it would be nice to have a minimal .bat file and/or ‘user.clj’ to enable the CLI deps experience/capabilities/tools programmatically via REPL. Am I over thinking or missing anything here? Perhaps by design or maybe it’s too early to ask for normative, idiomatic or canonical recommendations?

My initial question is a) how to start a REPL with ‘context’ that is ‘project-1 aware’? b) How to switch a REPL ‘context’ to be ‘project-n aware’?

I apologize I’m just starting out with CLI, deps.edn, tools.build, user.clj, etc. and have not absorbed many of the intricacies re required libraries, operational details, setup and intended use cases. Any suggestions would be greatly appreciated, thanks for sharing any insights!

1 Answer

0 votes
ago by

If you are using the Clojure CLI, then running clj in a directory will start a repl that has "project context" to the project deps.edn in that directory, and that is the way that most Clojure developers (regardless of editor) create a connected repl. (Alternately, they may be using Leiningen with a project.clj, but same idea.)

Typically you do not need tools.build / build.clj at all to create and work in a project until the point that you want to build and release an artifact. (Note that because the Clojure CLI / deps.edn support projects in public git repos like github, you don't necessarily ever need an artifact at all.) So I would ignore this aspect at the beginning, unless it affects your end goals.

It's unclear to me what you need at this point that you don't have. Do you need help with getting a project REPL connected in Emacs?

...