Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sometimes you want to use boot as a scripting platform on top of Leinengen. Paste this code at the top of your build.boot file. It reads in the project.clj file and stores it as a map named "project" which you can then use with `set-env!` to setup your environment.
(set-env! :dependencies '[[leiningen-core "2.5.0"]])
(use 'leiningen.core.project)
(eval (read-string (slurp "project.clj")))
(set-env!
:source-paths (:source-paths project)
:resource-paths (:resource-paths project)
:dependencies (:dependencies project))
;; Line 9 will replace the dependencies vector from line 1. If you want to merge them,
;; you might need to do #(into % (:dependencies project)) or something like that.

clows commented May 1, 2015

Above approach does load quite a few dependencies that conflict with other libraries being loaded.

This snipped has no outside dependencies and does pretty much the same thing (assuming you have a rather simple project.clj (It is not very robust)

  (def lein-proj 
  (->> 
    "project.clj" 
    slurp 
    read-string 
    (drop 3) 
    (partition 2) 
    (map vec) 
    (into {})))

(set-env!
 :source-paths   (into #{} (:source-paths lein-proj))
 :resource-paths (into #{} (:resource-paths lein-proj))
 :dependencies   (into [] (:dependencies lein-proj)))

I made this into a task and added it to the Boot wiki: https://github.com/boot-clj/boot/wiki/Using-Boot-in-a-Leiningen-Project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment