Skip to content

Commit

Permalink
Tell people to use profiles over middleware
Browse files Browse the repository at this point in the history
Along with replacing the unfortunate :injections example (ref technomancy#2033).
  • Loading branch information
hypirion committed Jan 18, 2016
1 parent 5cce823 commit 3b8d609
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,20 @@ opaqueness. If you can do what you need using profiles inside your
plugins instead, that is a much more declarative, introspectable way
to do things which will save a lot of headache down the line.

The following middleware injects the contents of project map into your
project's resources folder so it can be read from the project code:
The following middleware injects additional javac options into the project map,
but only if there are any java source paths in the project:

```clj
(ns lein-inject.plugin)
(ns lein-inject.plugin
(:require [leiningen.core.project :as p]))

(def javac-params-profile
{:javac-options ^:prepend ["-target" "1.6" "-source" "1.6"]})

(defn middleware [project]
(update-in project [:injections] concat
`[(spit "resources/project.clj" ~(prn-str project))]))
(if (seq (:java-source-paths project))
(p/merge-profiles project [javac-params-profile])
project))
```


Expand All @@ -341,6 +346,14 @@ that whenever we call `merge-profiles`, `unmerge-profiles` or
`set-profiles`. It also means your middleware functions shouldn't have
any non-idempotent side-effects since they could be called repeatedly.

If you need to include a profile in the project map, please add it as a plugin
profile and ask your users to add it to the `:base` profile as outlined in the
"Plugin" subsection of "Other Plugin Contents" in this document. This makes the
"injection" more explicit and easier to debug. The only times one should use
middleware to inject values into the project map is if the profiles has to be
programmatically computed, or if you have to modify the project map in a way
that is not possible with `merge-profiles`.

### Maven Wagons

[Pomegranate](https://github.com/cemerick/pomegranate) (the library
Expand Down

0 comments on commit 3b8d609

Please sign in to comment.