Getting Started with Clojure


The easiest way to get started with Clojure is through Leiningen.

I'll start creating a new Leiningen project running lein new app clojure-101 in my terminal. It will bootstrap a simple Clojure app.

Now change the directory and enter in the clojure-101 app folder then run lein run. It should display the default message "Hello, World".

I will update the file project.clj and include the Leiningen autorun plugin by including this line :plugins [[lein-auto "0.1.3"]]. The file will become the following:

(defproject clojure-101 "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url ""}
  :dependencies [[org.clojure/clojure "1.10.1"]]
  :main ^:skip-aot clojure-101.core
  :target-path "target/%s"
  :plugins [[lein-auto "0.1.3"]]
  :profiles {:uberjar {:aot :all
                       :jvm-opts [""]}})

Look in the line 9.

Now I'll run lein auto run in my terminal and this is the output:

> lein auto run

auto> Files changed: src\clojure_101\core.clj, test\clojure_101\core_test.clj
auto> Running: lein run
Hello, World!
auto> Completed.

Yay! My project is running automatically when I change any file.

This behavior is very useful to learn a new language. I need fast feedback and I don't understand the whole Clojure ecosystem to run REPL and plug that in my editor. I like to follow the easiest path that I already know.

I know how to develop using JavaScript and auto-reload server. I just want the same behavior while getting started with Clojure.

It is so easy that right now I can change the core.clj file and just print another message:

(ns clojure-101.core

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello darkness, my old friend"))

Looking at the terminal, I see the new message "Hello darkness, my old friend".

• • •

📝 Edit this page