README.md

lein-oneoff

Dealing with dependencies and the classpath can be a
pain. Leiningen takes most
of the pain away, but creating a new leiningen project for a simple
one-off script may sometimes feel like overkill. This is where
lein-oneoff comes in.

With the help of lein-oneoff you can open a file, declare
dependencies at the top, and write the rest of the code as
usually. lein-oneoff will let you run the file, open a repl or start a swank
server while taking care of fetching dependencies and constructing the
classpath automatically.

You might find lein-oneoff useful when you want to play with a brand
new alpha release of clojure, but would rather not dowload the jar
manually, when you think you know the answer to a question about a
particular library posted to the clojure mailing list, but would
rather test your idea out in the repl before posting the answer, or when
you quickly want to analyse and plot some data using
Incanter.

Usage

lein-oneoff scripts usually consist of a single file. Dependencies
should be stated at the top using the defdeps form. You may
optionally prefix the defdeps form with the reader macro #_ (ignore
next form). Here's an example:

This command will check the specified dependencies and install them
into the local maven repository (~/.m2/repository) unless already
installed, and then run example.clj with the necessary dependencies
in the classpath. Note that the dependencies are referenced directly
from the local maven repository.

The defdeps form

The defdeps form must be the first form in the file. It has the following
signature:

(defdeps dependencies additional-entries?)

where dependencies should be specified as a vector using the same
syntax as inside regular leiningen defproject form under the
:dependencies key. The second argument is an optional map of
additional standard defproject entries. Please note that not all of
the available leinigen options make sense for a one-off script and
might not work correctly. Adding a #_ prefix will make it possible
ignore the defdeps form when re-compiling the file in a repl.

One of the entries that can be useful is the :repositories entry. Here's
an example: