Leiningen tasks are simply functions named $TASK
in a leiningen.$TASK
namespace. So writing a Leiningen plugin is just a matter of creating
a project that contains such a function, but much of this
documentation applies equally to the tasks that ship with Leiningen
itself.
Using the plugin is a matter of declaring it in the :plugins
entry
of the project map. If a plugin is a matter of user convenience rather
than a requirement for running the project, users should place the
plugin declaration in the :user
profile in ~/.lein/profiles.clj
instead of directly in the project.clj
file.
The first thing to do when writing a plugin is to try to accomplish what you're doing without a plugin.
Early on in the days of Leiningen many plugins were written which did
nothing but provide a short command to run a specific function using
eval-in-project
. Once Leiningen added the support for
partially-applied aliases these became largely redundant, because you
could add an alias to the run
task:
:aliases {"mytest" ["run" "-m" "mylib.test/go"]}