07 November 2020

通过 https://jitpack.io/ 可以直接将 github 上的代码编译成 clojure 的 .jar 文件,并加载使用。这样就能很方便调试尚未发布到 clojars 的库了。

第一,在 project.clj 中添加相关 dependencies,以 clj-djl 为例:

  :dependencies [[org.clojure/clojure "1.10.1"]
                 ;;[clj-djl "0.1.2"]
                 [com.github.kimim/clj-djl "master-SNAPSHOT"]]

以上 [clj-djl "0.1.2"] 是发布到 clojars 的库,而 [com.github.kimim/clj-djl "master-SNAPSHOT"] 则是通过 jitpack 从 github repo 上的代码编译的最新版本。

第二,在 project.clj 中添加 repositories:

  :repositories [["jitpack" "https://jitpack.io"]]

第三,刷新 deps:

lein -U deps

完整 project.clj 如下:

(defproject clj-d2l "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.1"]
                 ;;[clj-djl "0.1.2"]
                 [com.github.kimim/clj-djl "master-SNAPSHOT"]
                 [dm3/stopwatch "0.1.1"]
                 [tech.tablesaw/tablesaw-core "0.38.1"]
                 [tech.tablesaw/tablesaw-jsplot "0.38.1"]
                 [com.hypirion/clj-xchart "0.2.0"]]
  :repositories [["jitpack" "https://jitpack.io"]]
  :main ^:skip-aot clj-d2l.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})