Back to Blog

Clojure for Beginners: Clojure Adding a Dependency — cheshire, deps.edn, and Maven Coordinates

Celest KimCelest Kim

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

Watch full page →

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

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.

Code

(ns app.core
  (:require [cheshire.core :as json]
            [clojure.java.io :as io]))

;; Adding a dependency: cheshire parses JSON into Clojure data.
;; deps.edn → {cheshire/cheshire {:mvn/version "5.13.0"}}

(defn load-book
  "Read resources/book.json and parse it as a Clojure map.
   The second argument `true` to parse-string keywordizes keys."
  []
  (-> (io/resource "book.json")
      slurp
      (json/parse-string true)))

(defn -main
  "Run with: clj -M:run"
  [& _]
  (let [book (load-book)]
    (println "Title :" (:title book))
    (println "Author:" (:author book))
    (println "Tags  :" (clojure.string/join ", " (:tags book)))
    (println "Pages :" (count (:pages book)))))

Key Points

Watch the video above for a full walkthrough — every keystroke is shown so you can code along.

Student code: GitHub