I have a Clojure “library” of common, project agnostic code i’ve accumulated over the years. Example structure:
├── deps.edn
├── src
│ └── toolkit
│ ├── data.clj
│ ├── db.clj
│ ├── db_lifecycle.clj
I have a project (call it A) currently referring to the above library as a local dep (`local/root`). In one of the namespace (`db_lifecycle`) there’s code in there which is only used in development. It also uses dev only deps. Nothing else depends on db_lifecycle . The issue is that when I go to build A, A wants me to include the deps used by db_lifecycle.
Is there a way to get A to build and just ignore db_lifecycle and the deps it uses (i’ve ensure nothing else uses this ns nor it’s deps)?I would like to say, “build toolkit but ignore toolkit/db-lifecycle”.
There is a lot to unpack there, but short answer is: no
Talking about "building" projects is kind of annoying because there is no one way to "build" a project. My guess is by "build" you mean aot compilation+uberjar
Yes, I meant compile.
If you aot compile by giving compile-clj your main namespace, and nothing transitively requires db-lifecycle it will never be loaded
But the deps in deps.edn are still what they are
There are two distinct dependencies systems, one at the project/artifact layer which is what deps.edn specifies and one at the level of clojure namespaces
So you need to tease apart which notions of dependencies you are interested in controlling where
I forget if it is default, but compile-clj has a mode where it searches for all clojure files on the class path, and builds a dependency graph (by analyzing ns forms) and then aot compiles them all in a topo sort order, which is likely what is causing db-lifecycle to get loaded.
Yes, this is what I imagine is triggering my issue and so I thought it might be possible to tell compile-clj to ignore an ns being added as part of the graph (because nothing uses it. It just lives in the same project dir)
Better to just give compile-clj your main entry point namespace and tell it to compile that
> Better to just give compile-clj your main entry point namespace and tell it to compile that This is what i’m currently doing.
So what is the thing that is the problem? db-lifecycle is getting aot compiled?
Or is it that your project A is getting transitive project level deps that are only used by db-lifecycle?
> Or is it that your project A is getting transitive project level deps that are only used by db-lifecycle? Yes, I believe it’s this.
Depending on how the project containing db-lifecycle is used, you could maybe move the deps for db-lifecycle into an alias (maybe even move db-lifecycle into a separate source tree that is only added to class path in the alias)