use*_*766 16 clojure leiningen
有没有办法在leiningen的项目中定义类似rake的任务.
我想在leiningen project.clj中定义一个自定义任务,它将在我的项目命名空间中调用一个函数
Leo*_*tny 20
您可以定义项目特定的别名,例如:
: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"]]}
Run Code Online (Sandbox Code Playgroud)
您应该能够将此功能与lein-exec
插件结合使用,以定义在项目中运行任意clojure代码的别名:
:aliases {"dosmth" ["exec" "-ep" "(use 'myproject.main) (foo 42)"]}
Run Code Online (Sandbox Code Playgroud)
现在您可以使用以下dosmth
任务lein
:
lein dosmth
Run Code Online (Sandbox Code Playgroud)
这只是一个别名
lein exec -ep "(use 'myproject.main) (foo 42)"
Run Code Online (Sandbox Code Playgroud)