tools-build

athomasoriginal 2024-12-23T17:42:20.318079Z

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)?

athomasoriginal 2024-12-23T17:44:20.669499Z

I would like to say, “build toolkit but ignore toolkit/db-lifecycle”.

2024-12-23T17:46:10.991819Z

There is a lot to unpack there, but short answer is: no

👍 1
2024-12-23T17:48:21.531069Z

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

athomasoriginal 2024-12-23T17:49:08.024659Z

Yes, I meant compile.

2024-12-23T17:49:59.575519Z

If you aot compile by giving compile-clj your main namespace, and nothing transitively requires db-lifecycle it will never be loaded

2024-12-23T17:50:24.285579Z

But the deps in deps.edn are still what they are

2024-12-23T17:52:08.318619Z

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

2024-12-23T17:52:59.279099Z

So you need to tease apart which notions of dependencies you are interested in controlling where

2024-12-23T17:55:44.832719Z

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.

athomasoriginal 2024-12-23T17:56:55.183699Z

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)

2024-12-23T17:57:45.619259Z

Better to just give compile-clj your main entry point namespace and tell it to compile that

athomasoriginal 2024-12-23T17:59:14.006489Z

> Better to just give compile-clj your main entry point namespace and tell it to compile that This is what i’m currently doing.

2024-12-23T18:00:08.572649Z

So what is the thing that is the problem? db-lifecycle is getting aot compiled?

2024-12-23T18:01:29.293489Z

Or is it that your project A is getting transitive project level deps that are only used by db-lifecycle?

athomasoriginal 2024-12-23T18:02:13.840589Z

> 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.

2024-12-23T18:03:47.287249Z

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)

👍 1