clojure - 在 leiningen 中定义项目特定任务

标签 clojure leiningen

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

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

最佳答案

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

关于clojure - 在 leiningen 中定义项目特定任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31175396/

相关文章:

clojure - 分解环形中间件场景

clojure - 是否可以在命名空间上下文中加载文件?

线程环境中的 Clojure 全局变量行为

clojure - Leiningen2、Clojure 和 Ring 的优秀 Web 服务教程是什么?

clojure - 如何将 Reduce-Realized 序列转回 Lazy Vector 序列

clojure - leiningen 运行一个 AOT 编译的 java 类

clojure - 在 lein repl 中传递命令行参数

macros - 双 Clojure/ClojureScript 库设计和宏

emacs - 连接到 swank-server 时出现异常

clojure - 无法使用 Leiningen 2.5.2 运行 uberjar