我有一个小的Clojure项目与/project.clj
:
(defproject testjackson "0.1.0-SNAPSHOT"
:main testjackson.core
:dependencies [[org.clojure/clojure "1.10.3"]
[ring/ring-json "0.5.0"]])
和/src/testjackson/core.clj
:
(ns testjackson.core
(:gen-class)
(:require [ring.middleware.json :refer [wrap-json-body]]))
(defn -main [& _] (println :testing wrap-json-body))
当我运行它时,它只是打印:
$ java -jar target/testjackson-0.1.0-SNAPSHOT-standalone.jar
:testing #object[ring.middleware.json$wrap_json_body 0x37cd92d6 ring.middleware.json$wrap_json_body@37cd92d6]
按预期运行。我也可以在uberjar上执行jdeps来获得使用的模块列表:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
java.base,java.desktop,java.sql,jdk.unsupported
但是,当我将ring-json
版本切换到0.5.1
时,jdeps调用失败:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.module.FindException: Module com.fasterxml.jackson.core not found, required by com.fasterxml.jackson.dataformat.smile
at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)
如何在这个小示例程序的上下文中解决这个问题?
就我所能从搜索中找到的,jdeps
来自Java 9。事实上,我电脑上的版本甚至不接受你在例子中使用的2个标志,它甚至没有--version
选项。Web搜索显示clojure没有明显的用途。
这里的目的是什么?您的纯代码对我来说很好:
项目。clj deps
:dependencies [
[org.clojure/clojure "1.11.1"]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.1"]
[tupelo "22.05.24b"]
]
:plugins [[com.jakemccrary/lein-test-refresh "0.25.0"]
[lein-ancient "0.7.0"]
]
代码(ns demo.core
(:use tupelo.core)
(:require [ring.middleware.json :refer [wrap-json-body]])
(:gen-class))
(defn -main [& _]
(spyx (type wrap-json-body)))
和结果
> lein clean ; lein run
(type wrap-json-body) => ring.middleware.json$wrap_json_body
投机虽然我的jlink
似乎不能正常工作,但我可以猜一点。看看project.clj
,我们可以请求一个依赖树:
> lein deps :tree
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.1"]
[cheshire "5.10.0"]
[com.fasterxml.jackson.core/jackson-core "2.10.2"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.10.2"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.10.2"]
[tigris "0.1.2"]
[ring/ring-core "1.9.2"]
[commons-fileupload "1.4"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.3"]
[commons-codec "1.15"]
我们看到ring-json需要cheshire, cheshire需要jackson。
回到ring-json 0.5.0,我们看到cheshire和jackson的不同版本:
> lein deps :tree
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
[cheshire "5.9.0"]
[com.fasterxml.jackson.core/jackson-core "2.9.9"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.9.9"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.9.9"]
[tigris "0.1.1"]
[ring/ring-core "1.7.1"]
[clj-time "0.14.3"]
[joda-time "2.9.9"]
[commons-fileupload "1.3.3"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.1"]
[commons-codec "1.11"]
请注意,如果您愿意,可以在project.clj
中强制更新版本。只需手动需要cheshire
和jackson
,并且将它们放在顶部!
:dependencies [
; priority 1 libs
[org.clojure/clojure "1.11.1"]
[cheshire "5.10.2"]
[com.fasterxml.jackson.core/jackson-core "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.13.3"]
; priority 2 libs
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
; [tupelo "22.05.24b"]
]
与结果
> lcr
time (lein do clean, run)
:type ring.middleware.json$wrap_json_body
8.11s user 0.59s system 218% cpu 3.989 total
~/expr/demo >
~/expr/demo >
~/expr/demo > lein deps :tree
[cheshire "5.10.2"]
[tigris "0.1.2"]
[com.fasterxml.jackson.core/jackson-core "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.13.3"]
[com.fasterxml.jackson.core/jackson-databind "2.13.3"]
[com.fasterxml.jackson.core/jackson-annotations "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.13.3"]
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
[ring/ring-core "1.7.1"]
[clj-time "0.14.3"]
[joda-time "2.9.9"]
[commons-fileupload "1.3.3"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.1"]
[commons-codec "1.11"]
也许类似的东西会解决你的问题。这在过去对我来说是至关重要的。
具体来说,jackson lib绝对必须在同一版本上拥有所有3个子库。因为从属lib通常不像Jackson那样尽可能频繁地更新自己的深度,当两个或更多的库每个都需要不同版本的Jackson时,很容易发生版本冲突。上述强制使用特定版本的jackson(或任何其他lib)的技术是一个救星。恕我直言,这也比试图放入一堆lein:exclusions
条款要好得多。