How do I start many ring subprojects with a single lein task?
题
I have a project with three subprojects like so (using lein-sub):
(defproject trident "0.1.0"
...
:sub
["admin"
"api"
"site"])
Each has a ring handler inside, something like this:
(defproject trident-api "0.1.0-SNAPSHOT"
...
:ring {:handler trident.api.core/handler
:servlet-name "trident-api"
:init trident.api.core/init
:port 33333})
Right now I go into each and type:
> lein ring server
This obviously gets tiresome. I also tried
> lein sub ring server
Which seems like it should work, but it only starts the first one and the process joins it! Possibly there is a way around that? It seems like this would be the simplest approach.
In lieu of that, I am now writing a leiningen task to do this for me, but am running into some issues. I can get the project file for each easily enough using leiningen.core.project/read, but from here, how do I start each ring server in a way that honors all of the dependencies and other settings from their respective project.clj files?
Any ideas?
解决方案 2
I ended up building a metaserver to start all three jetty instances at once. Code is here:
https://github.com/antler/lein-caribou/blob/master/src/leiningen/caribou/server.clj
其他提示
This is just a suggestion, as I am not able to verify if this will work right now.
There is a var in leiningen.core.project
that identifies default values. Maybe you could write a plugin (or fork lein-sub?) and have it override these values for the sub project? Then you can create a plugin that iterates over each sub project while applying a given task to each one.
For example, the defaults declares the source path like so:
:source-paths ["src"]
You could then override it with the following for each sub project:
:source-paths ["sub-project/src"]
Do that with all the pertinent defaults, and it might just work.
There might be a way to do this with Leiningen 2's profiles, but I'm not sure. I imagine if you create a profile for each sub project in the parent project, you could easily merge the profile when invoking the task on the respective sub project.