Skip to content
Tamas Herman edited this page Nov 2, 2016 · 12 revisions

Cursive's Leiningen support requires a project.clj file to be able to discover dependencies so it can resolve symbols in your source code.

To make sure your build.boot dependencies are kept in sync with what Cursive sees, it's recommended to just regenerate the project.clj every time boot starts.

The simplest way to do that is to use the boot.lein/generate boot task from the [onetom/boot-lein-generate] micro-library.

There is a reference project showcasing all this: https://github.com/onetom/hoplon-layouts

For further information, follow the related Cursive github issue: https://github.com/cursive-ide/cursive/issues/692#issuecomment-257907140

The original solution

Adding a lein-generate task as the one below can generate a project.clj file on the fly so Cursive knows what to do. And since you will need to use this task in all of your Cursive projects, it works best if you add the following code to your profile.boot file.

(defn- generate-lein-project-file! [& {:keys [keep-project] :or {keep-project true}}]
  (require 'clojure.java.io)
  (let [pfile ((resolve 'clojure.java.io/file) "project.clj")
        ; Only works when pom options are set using task-options!
        {:keys [project version]} (:task-options (meta #'boot.task.built-in/pom))
        prop #(when-let [x (get-env %2)] [%1 x])
        head (list* 'defproject (or project 'boot-project) (or version "0.0.0-SNAPSHOT")
               (concat
                 (prop :url :url)
                 (prop :license :license)
                 (prop :description :description)
                 [:dependencies (conj (get-env :dependencies)
                                      ['boot/core "2.6.0" :scope "compile"])
                  :repositories (get-env :repositories)
                  :source-paths (vec (concat (get-env :source-paths)
                                             (get-env :resource-paths)))]))
        proj (pp-str head)]
      (if-not keep-project (.deleteOnExit pfile))
      (spit pfile proj)))

(deftask lein-generate
  "Generate a leiningen `project.clj` file.
   This task generates a leiningen `project.clj` file based on the boot
   environment configuration, including project name and version (generated
   if not present), dependencies, and source paths. Additional keys may be added
   to the generated `project.clj` file by specifying a `:lein` key in the boot
   environment whose value is a map of keys-value pairs to add to `project.clj`."
 []
 (with-pass-thru fs (generate-lein-project-file! :keep-project true)))

(source)

Clone this wiki locally