Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define project specific tasks in leiningen

Is there a way to define rake like tasks within a project for leiningen.

I want to define a custom task in leiningen project.clj which will invoke a function in my project namespace

like image 361
user1896766 Avatar asked Jul 02 '15 04:07

user1896766


1 Answers

You can define project-specific aliases, e.g.:

  :aliases {"launch" ["run" "-m" "myproject.main"]
            ;; Values from the project map can be spliced into the arguments
            ;; using :project/key keywords.
            "launch-version" ["run" "-m" "myproject.main" :project/version]
            "dumbrepl" ["trampoline" "run" "-m" "clojure.main/main"]
            ;; :pass-through-help ensures `lein my-alias help` is not converted
            ;; into `lein help my-alias`.
            "go" ^:pass-through-help ["run" "-m"]
            ;; For complex aliases, a docstring may be attached. The docstring
            ;; will be printed instead of the expansion when running `lein help`.
            "deploy!" ^{:doc "Recompile sources, then deploy if tests succeed."}
            ;; Nested vectors are supported for the "do" task
            ["do" "clean" ["test" ":integration"] ["deploy" "clojars"]]}

You should be able to combine this feature with lein-exec plugin to define an alias to run arbitrary clojure code within your project:

  :aliases {"dosmth" ["exec" "-ep" "(use 'myproject.main) (foo 42)"]}

Now you can use dosmth task with lein:

lein dosmth

which is just an alias to

lein exec -ep "(use 'myproject.main) (foo 42)"
like image 90
Leonid Beschastny Avatar answered Oct 22 '22 16:10

Leonid Beschastny