In Leiningen versions 1.x.x I was able to define a lein foo
task valid only in a single project by putting the following in that project's 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))
You can get a little more information about this here:
http://nakkaya.com/2010/02/25/writing-leiningen-plugins-101/
In 2.x.x, I'm not able to do this anymore (i.e., I get 'foo' is not a task.
It seems way, way overkill for me to have to start a separate project for this task. Is it still possible to define a task within project.clj for leiningen 2.x.x?
The short answer is "no", but it is still fairly easy to define a project level task: Add :eval-in-leiningen true
to your defproject
definition and move the task definition to src/leiningen/foo.clj
.
You can do this by using .lein-classpath
to point to a directory outside of src
containing the tasks. For example, if you have the plugin in src/leiningen/foo.clj
, you can do, at the project root:
$ mkdir tasks
$ mv src/leiningen tasks/
$ echo tasks > .lein-classpath
The reason you might want to avoid :eval-in-leiningen true
is that it has some funny behaviors when you're trying to do AOT compilation for a main
class. Specifically, you get:
Compilation failed: java.io.IOException: No such file or directory, compiling:(testproj/core.clj:1)
When trying to compile/run a even a simple test example. More information at:
https://github.com/technomancy/leiningen/issues/769
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With