Skip to content

Run time requires (within task definitions)

Murphy McMahon edited this page Jul 20, 2015 · 1 revision

Requiring things at runtime

You may want your task itself to require namespaces, e.g. so that these namespaces don't need to be required globally in build.boot and affect startup time unnecessarily.

However a simple (require '[my-ns.tasks :refer [some-task]]) within deftask will not work, because when Clojure evaluates the file, all symbols in the code will be resolved and this isn't possible if you're doing the require at runtime.

One fix would be to resolve the symbols manually:

(deftask supertask []
  (require 'my-ns.tasks)
  (let [some-task (resolve 'my-ns.tasks/some-task)]
    (comp
     (some-task)
     ;; ... other tasks in your supertask pipeline ...
     )))
Clone this wiki locally