当使用 tools.deps 设置 monorepo 时,我注意到 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 的 prep 依赖
{: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