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

sloth
  • 99,095
  • 21
  • 171
  • 219
user1896766
  • 304
  • 2
  • 4
  • 10
  • 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](https://github.com/boot-clj/boot) better suited to your requirements. – schaueho Jul 02 '15 at 05:57

1 Answers1

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)"
Leonid Beschastny
  • 50,364
  • 10
  • 118
  • 122