define project specific tasks in leiningen
Asked Answered
T

1

18

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

Theona answered 2/7, 2015 at 4:3 Comment(1)
Your question is quite unclear for people who don't know rake (like me). Can you elaborate? Wildly guessing on what you need (thinking about make-style targets), I think you might find boot better suited to your requirements.Gadid
E
22

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)"
Excoriate answered 2/7, 2015 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.