Clojure Adding a Dependency — cheshire, deps.edn, and Maven Coordinates | Episode 23

0views
C
CelesteAI
Description
One line in `deps.edn` — a group/artifact and a Maven version — and a whole library is on your classpath. That's how Clojure projects pull in code from the ecosystem: through the Clojure CLI, backed by Clojars and Maven Central. In this episode we add `cheshire` — the de-facto JSON library for Clojure — and use it to parse a JSON file (`resources/book.json`) into a Clojure map. We edit `deps.edn`, restart the REPL to re-resolve dependencies, and run `(json/parse-string s true)` to see the ecosystem hand us a keywordized Clojure data structure. Student code: https://github.com/GoCelesteAI/clojure-for-beginners/tree/main/episode23 Every keystroke is shown on screen with generous pauses so you can follow along at your own pace. What You'll Learn: - Maven coordinates — `group/artifact` + `:mvn/version` - The `:deps` map in `deps.edn` — one entry per library - Restart the REPL after editing `deps.edn` (deps resolve at JVM startup, not at `:reload`) - `cheshire.core/parse-string` — JSON string to Clojure data - `true` as the second arg keywordizes keys - `(io/resource "book.json")` — read files from the resources path - Clojars vs Maven Central — where Clojure libs live, cached locally in `~/.m2` - Running the app from the REPL and from the shell (`clj -M:run`) Timestamps: 0:00 - Intro 0:15 - Preview: one coordinate, whole ecosystem 0:59 - Starting deps.edn (no dependencies yet) 1:21 - The JSON file we want to parse 1:44 - app.core — already requires cheshire 2:09 - Edit deps.edn: add the :deps map 2:40 - The new deps.edn with cheshire on the classpath 2:54 - Start the REPL 3:11 - Require cheshire.core as json 3:26 - parse-string on an inline JSON snippet 3:36 - Load app.core 3:46 - Run -main (book data parsed from disk) 3:52 - Control-D 4:16 - clj -M:run from the shell 4:32 - Recap 5:11 - What's next: Episode 24 Key Takeaways: 1. A dependency is a *coordinate*: `group/artifact` + a Maven version string. 2. You declare it once in the `:deps` map in `deps.edn` — the Clojure CLI resolves it at JVM startup. 3. After editing `deps.edn`, **restart the REPL**. `(require … :reload)` only reloads code already on the classpath — it won't pull new libraries. 4. `cheshire.core/parse-string` turns JSON into Clojure data. Pass `true` to keywordize the keys (so `{"k":1}` becomes `{:k 1}`). 5. Clojure-specific libraries live on Clojars; everything else on Maven Central. Both are cached in `~/.m2/repository` after first fetch. Next up: aliases and `deps.edn` workflows — `:extra-paths`, `:extra-deps`, and `:main-opts` patterns that make a project's build, test, and run commands self-documenting. Taught by CelesteAI. Like and subscribe for more Clojure tutorials!
Back to tutorials

Duration

Added to Codegiz

April 20, 2026

📖 Read the articleOpen in YouTube