gpt4 book ai didi

仅用于测试的 Clojure 依赖项

转载 作者:行者123 更新时间:2023-12-04 16:10:06 24 4
gpt4 key购买 nike

在我的 project.cli 中,我依赖于仅用于测试的 clj-http,以及 clj-http.client。

当我查看为该项目创建的 uberjar 文件时,我看到包含与此依赖项关联的类文件。这使得 jar 文件比需要的更大。

那么,有没有一种方法可以在 clojure 中定义依赖关系,使其仅在测试期间使用,而不包含在 uberjar 中?

我知道我可以在 pom.xml 中执行此操作,但 pom.xml 是在使用 clojure 时生成的,因此我只能求助于 project.clj 文件中的一些内容。

要添加更多颜色,我的 project.clj 看起来像这样

(defproject aproject "0.1.0-SNAPSHOT"
:description "A project"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/data.json "0.2.6"]
[compojure "1.5.0"]
[hiccup "1.0.5"]
[http-kit "2.1.18"]
[org.clojure/tools.logging "0.3.1"]
[ch.qos.logback/logback-classic "1.1.7"]
[ring/ring-devel "1.4.0"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler aproject.core/app-routes}
:main ^:skip-aot aproject.core
:target-path "target/%s"
:resources-paths ["resources/"]
:profiles {:uberjar {:aot :all}
:dev {:dependencies [[peridot "0.4.3"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]
:aliases {"test" ["midje"]}}
:test {:dependencies [[clj-http "3.5.0"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]}
})

我正在运行这样的测试:

lein with-profile test midje :filters dt

我看到的是:

Exception in thread "main" java.io.FileNotFoundException: Could not locate midje/util/ecosystem__init.class or midje/util/ecosystem.clj on classpath., compiling:(/private/var/folders/7l/0fwd_7ls1m19q3_z1_tgg1w80000gn/T/form-init7253661442775183594.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)

过滤器可能不会影响这一点,但以防万一测试看起来像这样:

(ns aproject.deployment.core
(:require [midje.sweet :refer :all]
[clj-http.client :as client]
[peridot.core :as p]
[clojure.data.json :as json]
[front-end.core :as fe]))

(facts "'aproject' deployed" :dt
(let [response (client/get "http://localhost:8080/ping")]
(response :status) => 200
))

我可以看到正在触发测试配置文件,我似乎对 midje 和插件有依赖性,但是......?

谢谢

内森

最佳答案

将其添加到 :test 配置文件,然后使用 lein with-profile test midje :filters dt 运行测试。像往常一样生成你的 uberjar,lein uberjar,它不应该包含额外的文件。

关于仅用于测试的 Clojure 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com