Skip to content
ninjudd edited this page Nov 17, 2011 · 4 revisions

Project Middleware

There has been some discussion in #leiningen and on the mailing list about allowing plugins to modify the defproject map. This basically makes plugins middleware for the project.

Why is this useful?

  • Plugins could use this to add things like repositories or deployment information to a project.
  • This would allow profiles/environments/contexts to be written as a plugin.
  • A company could spin-out common project.clj boilerplate into their own plugin to share among multiple projects.
  • This would make it easy for task dependencies (like those provided by cake's deftask) to be specified inside defproject. We could provide helper functions for plugins to add task dependencies to the project map.

What would this look like in practice?

  • Each plugin defines a function that will be called on the project map sequentially in the order plugins were required.
    • Classpath ordering seems like the way to go for determining precedence
  • One way to support this would be to require plugins to be named lein-* and define their project middleware wrapper in leiningen.plugins.*.
  • Another option is to put some info in the jar META-INF/MANIFEST.MF.

Another interesting observation is that defining the project using (def project ...) instead of (defproject ...), as suggested on the "Leiningen: the library" thread, allows you to use the threading operator to apply project middleware to the project map explicitly:

(def project 
  (-> {:name "yo" :group-id "yo" :version "1.0.0-SNAPSHOT" ...}
      protobuf.core/wrap-project
      configleaf.core/wrap-contexts))

Command-line arguments

Should command-line arguments be included in the project map so that plugins can use them for things like profile/environment/context specifiers? That would allow a context syntax like this:

lein deploy @prod
lein repl @qa
lein jar @native

An arg format that allows global args in addition to command specific args would allow more flexibility. Cake's argument parsing is worth looking at. Global options can be specified with -- args. For example:

lein test :functional --clean=true,all
;; :args {:test [":functional"] :clean ["true" "all"]}

Clone this wiki locally