2015-07-02 28 views
12

有没有一种方法可以在leiningen的项目中定义类似rake的任务。在leiningen中定义项目特定的任务

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

+1

你的问题的人谁不知道耙(像我)还不是很清楚。你能详细说明吗?大致猜测你需要什么(考虑make-style目标),我想你可能会发现[boot](https://github.com/boot-clj/boot)更适合你的需求。 – schaueho

回答

17

您可以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)"