dot-clojure
This is my personal .clojure/deps.edn
file providing useful clj
aliases drawn from a variety of projects. It is published to GitHub so I can keep all my computers sync'd up -- and to provide a range of examples that folks new to the Clojure CLI might find helpful.
Several git dependencies here assume you have at least Clojure CLI 1.11.1.1273!
In addition, my .clojure/tools/
folder is also here, containing the tools that I've installed globally, via the latest Clojure CLI (was 1.11.1.1273 when I last updated this) -- see Tool installation and invocation in the Deps and CLI Reference. As I add global tools, I am removing them as aliases.
The main alias I use here is :dev/repl
which starts various combinations of REPL tooling. See The :dev/repl
Alias below for more details.
Since it is my personal file, it may make assumptions about my own environment. For example, it uses "RELEASE"
for several tools so I can always get the latest stable version of any dev/test tool I use. I make no effort at backward-compatibility and may add, delete, or change aliases as they benefit me personally. Caveat Programmer!
If you want a really well-documented, well-maintained alternative that actually tracks versions of tools, I would recommend you use the Practicalli Clojure deps.edn
project instead!
With that caveat out of the way, here is some basic documentation about my tools and aliases (there are additional examples in the comments in the deps.edn
file itself). Note: I have recently cleaned this file up and removed a lot of aliases I no longer use!
TL;DR: add the following dependency and then start a REPL with clj -M:dev/repl
(optionally with other aliases to bring in more tooling):
:aliases
{:dev/repl
{:extra-deps
{io.github.seancorfield/dot-clojure
{:git/tag "v1.0.2"
:git/sha "6a3f903"}}
:main-opts ["-e" "((requiring-resolve 'org.corfield.dev.repl/start-repl))"]}}
Basic Tools
These are installed via clojure -Ttools install ...
and usable via clojure -T
with the tool name.
antq
-- the outdated dependencies checker:clojure -Tantq outdated
-- check the current project's dependencies,clojure -A:deps -Tantq help/doc
-- for more information and other functions.
clj-watson
-- a software composition analysis scanner, based on the National Vulnerability Database: clj-watsonclojure -Tclj-watson scan :deps-edn-path '"deps.edn"' :output '"stdout"'
new
-- the latest version of deps-new to create new CLI/deps.edn
projects: [This uses a different (simpler!) templating system toclj-new
, below, and therefore does not recognize Leiningen or Boot templates!]clojure -Tnew app :name myname/myapp
-- creates a newdeps.edn
-based application project,clojure -Tnew lib :name myname/mylib
-- creates a newdeps.edn
-based library project,clojure -Tnew template :name myname/mytemplate
-- creates a newdeps.edn
-based template project,clojure -A:somealias -Tnew create :template some/thing :name myname/myapp
-- locates a template forsome/thing
on the classpath, based on:somealias
, and uses it to create a newdeps.edn
-based project,clojure -A:deps -Tnew help/doc
-- for more information and other functions.
poly
-- a recent master version of Polylith'spoly
tool for working with Polylith projects:clojure -Tpoly shell
-- start an interactive Polylith shell,clojure -Tpoly info :loc true
-- display information about a Polylith workspace, including lines of code,clojure -Tpoly create c user
-- create auser
component in a Polylith workspace,clojure -Tpoly test :dev true
-- run tests in thedev
project context, in a Polylith workspace,clojure -A:deps -Tpoly help/doc
-- for more information and other functions.
And the older clj-new
tool:
clj-new
-- the latest stable release of clj-new to create new projects from (Leiningen and other) templates:clojure -Tclj-new app :name myname/myapp
-- creates a newdeps.edn
-based application project (usingtools.build
for the uberjar),clojure -Tclj-new lib :name myname/mylib
-- creates a newdeps.edn
-based library project (usingtools.build
for the jar),clojure -Tclj-new template :name myname/mytemplate
-- creates a newdeps.edn
-based template project (usingtools.build
for the jar),clojure -Tclj-new create :template something :name myname/myapp
-- locates a template forsomething
and uses it to create a new project (which might bedeps.edn
-based orlein
-based, depending on the template),clojure -A:deps -Tclj-new help/doc
-- for more information and other functions.
More tools will be added to this section over time (as more tools add :tools/usage
to their deps.edn
files).
Basic Aliases
Deploy jar files (if you don't have a build.clj
file):
:deploy
-- pulls in and runs the latest stable release of Erik Assum's deps-deploy and deploys the specified JAR file to Clojars, based on yourpom.xml
and theCLOJARS_USERNAME
andCLOJARS_PASSWORD
environment variables;clojure -X:deploy :artifact '"MyProject.jar"'
There are aliases to pull in various useful testing and debugging tools:
:test
-- adds bothtest
andsrc/test/clojure
to your classpath and pulls in the latest stable version oftest.check
:runner
-- pulls in Cognitect Labs'test-runner
project and runs any tests it can find:eastwood
-- pulls in the latest stable release of Eastwood on yoursrc
andtest
folders; use with:test
above:check
-- pulls in Athos' Check project to compile all your namespaces to check for syntax errors and reflection warnings likelein check
:expect
-- pulls in the latest stable release of expectations/clojure-test -- theclojure.test
-compatible version of Expectations:bench
-- pulls in the latest stable release of Criterium for benchmarking your code
There are aliases to pull in and start various REPL-related tools:
-
:dev/repl
-- depending on what is on your classpath, start Rebel Readline, with a Socket REPL (if requested -- note that "port 0" will dynamically select an available port and print it out), butSOCKET_REPL_PORT
env var andsocket-repl-port
property override, saves port to.socket-repl-port
file for next time;- usage:
clj -M:portal:dev/repl
-- basic REPL with Portal orclojure -M:rebel:dev/repl
-- Rebel Readline REPL orclojure -M:rebel:portal:dev/repl
-- ...with Portal orclojure -M:nrepl:dev/repl
-- basic nREPL server orclojure -M:nrepl:portal:dev/repl
-- basic nREPL server with Portal middleware orclojure -M:cider-nrepl:dev/repl
-- CIDER nREPL server orclojure -M:cider-nrepl:portal:dev/repl
-- CIDER nREPL server with Portal middleware or
- Also works with Figwheel Main (now that I've started doing ClojureScript!):
clojure -M:portal:fig:build:dev/repl
or
- usage:
-
:classes
-- adds theclasses
folder to your classpath to pick up compiled code (e.g., see https://clojure.org/guides/dev_startup_time) -
:socket
-- starts a Socket REPL on port 50505; can be combined with other aliases since this is just a JVM option -
:rebel
-- starts a Rebel Readline REPL -
:nrepl
-- starts a (headless) nREPL server on a random available port;clojure -M:nrepl
-
:cider-nrepl
-- starts a (headless) CIDER-enhanced nREPL server on a random available port;clojure -M:cider-nrepl
-
:datomic/dev.datafy
-- addsdatafy
/nav
support for Datomic objects via datomic/dev.datafy -
:dbxray
-- adds donut-party/dbxray to help visualize your database structure -
:jedi-time
-- addsdatafy
/nav
support for Java Time objects via jedi-time -
:portal
-- pulls in the latest stable release of the Portal data visualization tool -- see the Portal web site for usage options -
:reflect
-- adds Stuart Halloway's reflector utility (best used with Portal)
There are aliases to pull in specific versions of Clojure:
:master
-- Clojure 1.12.0-master-SNAPSHOT:1.12
-- Clojure 1.12.0-alpha4:1.11
-- Clojure 1.11.1 -- see changes to Clojure in version 1.11.1:1.11.0
-- Clojure 1.11.0
:1.10
-- Clojure 1.10.3:1.10.2
-- Clojure 1.10.2:1.10.1
-- Clojure 1.10.1:1.10.0
-- Clojure 1.10.0
:1.9
-- Clojure 1.9.0:1.8
-- Clojure 1.8.0- ... back to
:1.0
(note::1.5
is actually Clojure 1.5.1 to avoid a bug in Clojure 1.5.0, and:1.2
is 1.2.1)
Note: the EXPERIMENTAL
:add-libs
alias has been removed -- use theclojure.repl.deps
in Clojure 1.12.0 Alpha 2 or later instead!
:dev/repl
Alias
The The :dev/repl
alias calls org.corfield.dev.repl/start-repl
in the repl.clj
file from this repo. That does a number of things (see the start-repl
docstring for more details):
- Optionally, starts a Socket REPL server (with the port selected via an environment variable, a JVM property, or a dot-file created on a previous run).
- If both Portal and
org.clojure/tools.logging
are on the classpath, it patchtools.logging
to alsotap>
every log message in a format that Portal understands and can display (usually with the ability to go to the file/line listed in the log entry); call(dev/toggle-logging!)
to turn thistap>
'ing on and off. - If Portal 0.33.0 or later is on the classpath, use the Portal middleware with nREPL (if CIDER or nREPL are on the classpath). If using Portal 0.40.0 or later, this also adds the Portal Notebook middleware.
- Starts Figwheel Main, if present on the classpath, else
- Starts Rebel Readline, if present on the classpath, else
- Starts a CIDER-enhanced nREPL Server, if
cider-nrepl
is present on the classpath, else - Starts an nREPL Server, if present on the classpath.
Note 1: since the repl.clj
code uses requiring-resolve
, it requires at least Clojure 1.10.0!
Note 2: if the Portal middleware is added to nREPL/CIDER, all evaluated results will be tap>
'd (if the Portal UI is open and listening); my VS Code/Calva setup has additional configuration for working with Portal when the middleware is enabled!
Use with Figwheel
If you are doing ClojureScript development with Figwheel (figwheel-main
) then you can do something like:
clojure -M:portal:fig:build:dev/repl
You'll get the regular Figwheel build REPL (for ClojureScript, which uses Rebel Readline) and a browser open on your application, plus a Socket REPL on an available port (or whatever your env says, for Clojure evaluation).
Connect to the Socket REPL, write your code as .cljc
files, and you'll have the full power of your editor, Portal, and Figwheel! What you evaluate in your editor will be treated as Clojure code (and can be tap>
'd into Portal, for example). What you evaluate at the REPL itself will be treated as ClojureScript code (and will affect your application instead).
License
Copyright © 2018-2023 Sean Corfield
Distributed under the Apache Software License version 2.0.