在设置 monorepo 时使用 tools.deps,我发现 clojure -X:deps prep
没有处理嵌套的 :local/root
依赖情况。下面是一个有助于理解问题的最小示例。
我有一个顶层的 deps.edn
,作为开发基础,取决于两个模块。
{:deps {monopero/module-a {:local/root "modules/a"}
monopero/module-b {:local/root "modules/b"}}}
这是 module/a/deps.edn
,这是一个没有依赖的模块。
{:paths ["src"]}
这是 module/b/deps.edn
,它仅对模块 A 定义了预备依赖。
{:paths ["target/resources"]
:deps/prep-lib {:alias :resources
:fn monorepo.b.core/generate
:ensure "target/resources"}
:aliases {:resources {:paths ["src"]
:deps {monopero/module-a {:local/root "../a"}}}}}
从顶层开发基础出发,我预期能够运行 clojure -X:deps prep
触发模块 B 的准备。然而,当我这样做时,我遇到了以下错误。
~/src/scratch/recur-prep $ clojure -X:deps prep
Prepping monopero/module-b in /home/mthl/src/scratch/recur-prep/modules/b
Execution error (ExceptionInfo) at clojure.tools.deps.alpha.extensions/throw-bad-manifest (extensions.clj:158).
Manifest type not detected when finding deps for monopero/module-a in coordinate #:local{:root "/home/mthl/src/scratch/a"}
Full report at:
/tmp/clojure-5135322536447899533.edn
以下是内容 /tmp/clojure-5135322536447899533.edn
{:clojure.main/message
"Execution error (ExceptionInfo) at clojure.tools.deps.alpha.extensions/throw-bad-manifest (extensions.clj:158).\nManifest type not detected when finding deps for monopero/module-a in coordinate #:local{:root \"/home/mthl/src/scratch/a\"}\n",
:clojure.main/triage
{:clojure.error/class clojure.lang.ExceptionInfo,
:clojure.error/line 158,
:clojure.error/cause
"Manifest type not detected when finding deps for monopero/module-a in coordinate #:local{:root \"/home/mthl/src/scratch/a\"}",
:clojure.error/symbol
clojure.tools.deps.alpha.extensions/throw-bad-manifest,
:clojure.error/source "extensions.clj",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type clojure.lang.ExceptionInfo,
:message
"Manifest type not detected when finding deps for monopero/module-a in coordinate #:local{:root \"/home/mthl/src/scratch/a\"}",
:data
{:lib monopero/module-a,
:coord {:local/root "/home/mthl/src/scratch/a"}},
:at
[clojure.tools.deps.alpha.extensions$throw_bad_manifest
invokeStatic
"extensions.clj"
158]}],
:trace
[[clojure.tools.deps.alpha.extensions$throw_bad_manifest
invokeStatic
"extensions.clj"
158]
[clojure.tools.deps.alpha.extensions$throw_bad_manifest
invoke
"extensions.clj"
153]
[clojure.tools.deps.alpha.extensions$eval443$fn__444
invoke
"extensions.clj"
166]
[clojure.lang.MultiFn invoke "MultiFn.java" 244]
[clojure.tools.deps.alpha$expand_deps$children_task__611$fn__613$fn__614
invoke
"alpha.clj"
405]
[clojure.tools.deps.alpha.util.concurrent$submit_task$task__247
invoke
"concurrent.clj"
35]
[clojure.lang.AFn call "AFn.java" 18]
[java.util.concurrent.FutureTask run "FutureTask.java" 264]
[java.util.concurrent.ThreadPoolExecutor
runWorker
"ThreadPoolExecutor.java"
1128]
[java.util.concurrent.ThreadPoolExecutor$Worker
run
"ThreadPoolExecutor.java"
628]
[java.lang.Thread run "Thread.java" 829]],
:cause
"Manifest type not detected when finding deps for monopero/module-a in coordinate #:local{:root \"/home/mthl/src/scratch/a\"}",
:data
{:lib monopero/module-a,
:coord {:local/root "/home/mthl/src/scratch/a"}}}}
据我理解,问题在于模块 B 中的 "../a" 本地引用是从顶层目录解析的,而不是模块 B 目录。在查看代码时,我发现 clojure.tools.deps.alpha/prep-libs!
在创建基础时没有更改当前目录。我的直觉是,它应该通过以下代码片段来执行:
(let [root-dir (jio/file root)
basis (dir/with-dir root-dir
(create-basis
{:extra {:aliases {:deps/TOOL {:replace-deps {} :replace-paths ["."]}}}
:aliases [:deps/TOOL alias]}))
,,,]
,,,)
如果这很重要,我正在使用 Clojure CLI 版本 1.11.1.1113