在Leiningen版本1.x.x中,通过在项目的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.x.x中,我不能再这样做了(也就是说,我得到了'foo' is not a task. --这对我来说似乎太过了,我不得不为这个任务启动一个单独的项目。仍然可以在project.clj中为Leiningen2.x.x?定义任务吗?
发布于 2012-09-03 23:49:00
简短的回答是“否”,但定义项目级别的任务仍然相当容易:将:eval-in-leiningen true添加到defproject定义中并将任务定义移动到src/leiningen/foo.clj。
发布于 2012-09-07 02:28:11
可以通过使用.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://stackoverflow.com/questions/12240439
复制相似问题