Thursday, April 9, 2015

Clojure command line script with dependencies

If you want to use Clojure for command line scripts, the easiest way is by using lein-exec plugin. It compiles clj files on the fly and downloads all necessary dependencies that are declared in same file, similarly to Groovy @Grab annotation.

For example, if you have file named download.clj with
(leiningen.exec/deps '[[http-kit "2.1.16"]])
(require '[org.httpkit.client :as http])

(prn (:body @(http/get "http://www.google.com")))


it is possible to run it by:
lein exec download.clj

No comments:

Post a Comment