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 yourdefproject
definition and move the task definition tosrc/leiningen/foo.clj
.You can do this by using
.lein-classpath
to point to a directory outside ofsrc
containing the tasks. For example, if you have the plugin insrc/leiningen/foo.clj
, you can do, at the project root: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 amain
class. Specifically, you get:When trying to compile/run a even a simple test example. More information at:
https://github.com/technomancy/leiningen/issues/769