Monorepo is the way to manage several related projects from one point. In this note I'll show you how to organize monorepo using Amperity plugin lein-monolith .
0. Lets create root project and some subprojects
rootproject
project.clj ;;project file for root project
/apps
/app01 ;; project folder for app01 project
/libs
/lib01 ;; project folder for lib01 project which is needed for app01
/lib02 ;; some other lib
1. We should put section :plugins [[lein-monolith "1.0.1"]] to root project.clj and to project.clj of all subprojects.
2. Every project.clj of all subprojects we prepare like this:
3. Now we can run commands from root project
Interesting fact that we can point out clojure version only in root project - project.clj, in section :managed-dependencies and this version of clojure will be delivered to all subprojects. So we don't need to include clojure version in subprojects.
Also from root project we can run different tests for different subproject using selectors. First of all wee should put metadata to all deftest like here
https://github.com/technomancy/leiningen/blob/2.4.3/src/leiningen/test.clj#L164
In example above it is integrations test with ^:integration metadata. Then we should put section
in root project.clj and put :test-selectors to :inherit section.
0. Lets create root project and some subprojects
rootproject
project.clj ;;project file for root project
/apps
/app01 ;; project folder for app01 project
/libs
/lib01 ;; project folder for lib01 project which is needed for app01
/lib02 ;; some other lib
1. We should put section :plugins [[lein-monolith "1.0.1"]] to root project.clj and to project.clj of all subprojects.
2. Every project.clj of all subprojects we prepare like this:
3. Now we can run commands from root project
lein monolith each do clean, uberjarThis command will clean and make uberjars for all subprojects. Remember, that we should run
lein installfor lib01 to install to a local repo for app01 which use it. Also we can run command only for particular subproject
lein monolith each :start rootproject/app01 do uberjarThis command will run uberjar target only for particular project.
Interesting fact that we can point out clojure version only in root project - project.clj, in section :managed-dependencies and this version of clojure will be delivered to all subprojects. So we don't need to include clojure version in subprojects.
Also from root project we can run different tests for different subproject using selectors. First of all wee should put metadata to all deftest like here
https://github.com/technomancy/leiningen/blob/2.4.3/src/leiningen/test.clj#L164
In example above it is integrations test with ^:integration metadata. Then we should put section
:test-selectors | |
{:unit (complement :integration) | |
:integration :integration} |
in root project.clj and put :test-selectors to :inherit section.