Leiningen 如何将依赖项包含在结果 jar 文件中

Leiningen how to include dependency into result jar file

提问人:Freeze Dolphin 提问时间:4/22/2023 最后编辑:Freeze Dolphin 更新时间:4/24/2023 访问量:61

问:

(defproject dumortierite "0.1.0-SNAPSHOT"
 
  ;; omitted...

  :dependencies [
                 [com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]

                 [org.clojure/clojure "1.11.1" :scope "provided"]
                 [io.papermc.paper/paper-api "1.19.3-R0.1-SNAPSHOT" :scope "provided"]
                 [com.github.StarWishsama/Slimefun4 "2023.02" :scope "provided"]
                ])

我添加了 4 个依赖项,我只想包含在
构建结果 jar
[com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]

如果使用 ,它将在 jar 中包含所有这 4 个 dep。lein uberjar

我知道这可以通过使用 in 来完成,但是如何在 中?shademavenleiningen


我在下面尝试过:

:dependencies [[com.github.freeze-dolphin/clamp "4ddd923dcb"]]
  :profiles {:dev
             {:dependencies
              [
               [com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]
               ]}
             :provided
             {:dependencies
              [
               [org.clojure/clojure "1.11.1" :scope "provided"]
               [io.papermc.paper/paper-api "1.19.3-R0.1-SNAPSHOT" :scope "provided"]
               [com.github.StarWishsama/Slimefun4 "2023.02" :scope "provided"]
               ]}}

但在 中,不包含 deps。
而在 中,一切都包含在内......
jaruberjar

Clojure Leiningen

评论

0赞 cfrick 4/24/2023
将内容放在配置文件中,应该可以防止它们出现在 uberjar 中。难道这两个不需要的 dep 也是来自你的库的(可传递的)deps?:providedclamp

答:

0赞 Denis Fuenzalida 4/24/2023 #1

作为解决方法,您可以在 with 中使用正则表达式向量,这些向量将用于匹配项目中的文件名。任何匹配都会导致文件打包到 Uberjar 中。:uberjar-exclusionsproject.clj

我在具有以下依赖项的示例项目上对其进行了测试:

  :dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
                 [commons-codec/commons-codec "1.15"]]

为了从 Uberjar 中排除文件,我使用了:commons-codec

:profiles {:uberjar {:aot :all
                     :uberjar-exclusions [#"org/apache/commons/codec"
                                          #"META-INF/maven/commons-codec"]
                     :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}

原始示例位于 Leiningen 的示例 project.clj 中。