11

在 Leiningen 版本 1.xx 中,我可以lein foo通过在该项目中添加以下内容来定义仅在单个项目中有效的任务project.clj

(defproject tester "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.4.0"]])

;; Create a task, "foo"

(ns leiningen.foo
  (:require (leiningen [uberjar :as uberjar])))

(defn foo [project & args]
  (println "Do something here first, then make the uberjar.")
  (uberjar/uberjar project))

您可以在此处获得有关此的更多信息:

http://nakkaya.com/2010/02/25/writing-leiningen-plugins-101/

在 2.xx 中,我无法再执行此操作(即,我得到了'foo' is not a task. 似乎方式,对我来说必须为此任务启动一个单独的项目有点过分了。 是否仍然可以在 project.clj 中定义一个任务对于 leiningen 2.xx?

4

2 回答 2

5

简短的回答是“否”,但定义项目级任务仍然相当容易:添加:eval-in-leiningen true到您的defproject定义并将任务定义移动到src/leiningen/foo.clj.

于 2012-09-03T23:49:00.447 回答
4

您可以通过使用.lein-classpath指向src包含任务之外的目录来执行此操作。例如,如果您有插件src/leiningen/foo.clj,您可以在项目根目录中执行以下操作:

$ mkdir tasks
$ mv src/leiningen tasks/
$ echo tasks > .lein-classpath

您可能要避免的原因:eval-in-leiningen true是,当您尝试为main类进行 AOT 编译时,它会出现一些有趣的行为。具体来说,你会得到:

Compilation failed: java.io.IOException: No such file or directory, compiling:(testproj/core.clj:1)

当尝试编译/运行一个简单的测试示例时。更多信息请访问:

https://github.com/technomancy/leiningen/issues/769

于 2012-09-07T02:28:11.077 回答