在莱宁根定义项目特定任务

时间:2015-07-02 04:03:40

标签: clojure leiningen

有没有办法在leiningen的项目中定义类似rake的任务。

我想在leiningen project.clj中定义一个自定义任务,它将在我的项目命名空间中调用一个函数

1 个答案:

答案 0 :(得分:18)

你可以define project-specific aliases,例如:

  :aliases {"launch" ["run" "-m" "myproject.main"]
            ;; Values from the project map can be spliced into the arguments
            ;; using :project/key keywords.
            "launch-version" ["run" "-m" "myproject.main" :project/version]
            "dumbrepl" ["trampoline" "run" "-m" "clojure.main/main"]
            ;; :pass-through-help ensures `lein my-alias help` is not converted
            ;; into `lein help my-alias`.
            "go" ^:pass-through-help ["run" "-m"]
            ;; For complex aliases, a docstring may be attached. The docstring
            ;; will be printed instead of the expansion when running `lein help`.
            "deploy!" ^{:doc "Recompile sources, then deploy if tests succeed."}
            ;; Nested vectors are supported for the "do" task
            ["do" "clean" ["test" ":integration"] ["deploy" "clojars"]]}

您应该能够将此功能与lein-exec plugin结合使用,以定义在项目中运行任意clojure代码的别名:

  :aliases {"dosmth" ["exec" "-ep" "(use 'myproject.main) (foo 42)"]}

现在,您可以dosmth使用lein任务:

lein dosmth

这只是

的别名
lein exec -ep "(use 'myproject.main) (foo 42)"