amperity / lein-monolith

Leiningen plugin for working with monorepos.
Other
214 stars 18 forks source link

loading the inheritance of a subproject into an ide repl #22

Closed drorbemet closed 7 years ago

drorbemet commented 7 years ago

Hi, first thanks for publishing your approach for the management of clojure projects. It's a great encouragement for me to continue applying clojure on a growing variety of tasks.

My question: Do I have to avoid :monolith :inherit when developing using a repl on a subproject?

While trying to figure out which use cases lein-monolith does address and which it doesn't I came accross the question if it's intended to to support inheritance of dependencies in an IDE-repl on a subproject?

Using cider (cider-jack-in) on an extended version of example/app-a I found that inherited dependencies (:monolith/inherit true) are not available. But when I run tests depending on an inherited dependency using lein monolith each :in app-a test everything gets loaded as expected.

I put the new dependency (me.raynes/fs) in the metaproject definition like this:

(defproject example/all "MONOLITH"
;; ...
:dependencies
  [[org.clojure/clojure "1.8.0"]
   [me.raynes/fs "1.4.6"]]
  :managed-dependencies
  [[me.raynes/fs "1.4.6"]]

  :monolith
  {:inherit
   [:repositories
    :test-selectors
    ;; :managed-dependencies ;; what is this for?
    :dependencies  ;; this seems to work
    ;; :plugins ;; inheriting plugins too, or better using lein profiles :user :plugins ?
    ]
;; ...
)

And in app-a I am testing if me.raynes/fs gets loaded like this:

(ns project-a.core-test
  (:require [clojure.test :refer :all]
            [project-a.core :refer :all]
            [me.raynes.fs :as fs]))

(deftest a-app-test
  (is true))

(deftest b-app-test
  (is (= java.io.File (type (fs/temp-dir "t")))))

What am I missing here?

Thanks for any hints helping me to apply lein-monolith to my workflow. PS: I didn't find a recording of the talk about lein-monolith on the web, is there some? Thanks to Derek Slager for mentioning it on clojure/west though.

greglook commented 7 years ago

I think the main thing you're missing is having lein-monolith present in your user or system profiles. When running from the metaproject, monolith gets picked up out of the plugins in the project.clj file, and when running the each command the inherited profile is properly injected into each subproject based on the :monolith/inherit key. In contrast, if you run a lein task in a subproject which doesn't have the plugin and it's not available globally from your user profile, then there's nothing telling leiningen to do anything with that :monolith/inherit key.

You probably don't need :managed-dependencies - that's for setting global dependency versions. I'm not sure exactly how your editor integrates with user plugins, but I'd start by adding lein-monolith there.

There's no recording of the talk, just the slides since it was a local meetup.

drorbemet commented 7 years ago

Actually I did add lein-monolith to my global :user :plugins but after that I had a stale repl instance. Dah!

{:user {:plugins [[lein-monolith "0.3.2"]]}}

Thanks.