簡體   English   中英

如果我在結帳中有依賴項,如何使用 lein uberjar 創建 Clojure 應用程序?

[英]How do I create a Clojure application with lein uberjar if I have a dependency in checkouts?

我有一個 Clojure 應用程序,該應用程序正在使用從“結帳”目錄內部符號鏈接的庫。

這讓我可以同時處理應用程序和庫。 lein 知道如何毫無問題地編譯和運行程序。

但我想用 lein uberjar 做一個獨立的,它在抱怨

Caused by: java.io.FileNotFoundException: Could not locate mylib/core__init.class, mylib/core.clj or mylib/core.cljc on classpath.

我認為這是因為我的 project.clj 文件中沒有提到 mylib。 不是,正是因為我想在“結帳”中使用符號鏈接的 mylib 版本。

但是uberjar命令好像看不到。

我該如何解決這個問題?

您可以通過在本地存儲庫 (~/.m2/repository) 中安裝mylib來完成此操作。

  1. 在依賴項目中運行lein install以將其安裝到本地存儲庫中。
  2. 將項目添加到project.clj中的:dependencies :

    [mylib "version"]

  3. 在主項目中運行lein uberjar

該項目將在您的本地存儲庫中找到 jar。

/編輯

如果您想同時開發兩個庫,您可以使用 checkouts 文件夾,其中 checkouts 包含指向依賴庫的符號鏈接。

mkdir checkouts
ln -nfs full-path-other-lib-dir full-path-checkouts-dir

現在 other-lib 中的更改可以立即在主項目中使用。

請參閱 [ https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies]( Leiningen 結帳文檔)。

好的,似乎 lein 的“結帳”功能適用於lein testlein run但不適用於lein uberjar

我將以下內容添加到 lib tupelo.core的本地源代碼中:

(def dummy-sample-data "Bogus!")

在消費項目demo.core ,我們可以訪問新的 Var:

(ns demo.core
  (:use tupelo.core tupelo.test))

(defn -main [& args]
  (println :foo-enter)
  (spyx dummy-sample-data)
  (println :foo-leave))

lein run產生:

:foo-enter
dummy-sample-data => "Bogus!"
:foo-leave

project.clj保持不變:

(defproject demo "0.1.0-SNAPSHOT"
  :license {:name "Eclipse Public License"
            :url  "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
     [criterium "0.4.5"]
     [org.clojure/math.combinatorics "0.1.6"]
     [org.clojure/clojure "1.10.1"]
     [prismatic/schema "1.1.12"]
     [tupelo "0.9.201"]
   <snip>

其中"0.9.201"tupelo上 tupelo 的最新版本。 結帳看起來像:

~/expr/demo > ls -ldF checkouts/*
lrwxrwxrwx 1 alan alan 17 May 12 13:57 checkouts/tupelo -> /home/alan/tupelo/

但 uberjar 失敗:

~/expr/demo > lein clean ; lein uberjar
Compiling demo.core
Syntax error compiling at (demo/core.clj:6:3).
Syntax error compiling at (demo/core.clj:6:3).
Unable to resolve symbol: dummy-sample-data in this context

Full report at:
/tmp/clojure-10416346559924917196.edn
Compilation failed: Subprocess failed

選項

如果要部署應用程序,您有 2 個選項:

  1. 如果 lib 存在於 Clojars 或 Maven 上,您可能應該在制作 uberjar 之前在那里部署一個版本。 如果該庫尚未准備好用於 Clojars 或 Maven,也許您還沒有准備好在 uberjar 中使用它......?

  2. 只需在項目中的./src目錄下復制mylib的源代碼樹(或使用符號鏈接!)。 您還必須將依賴項復制到myproj/project.clj中。 您正在有效地合並 myproj 和 mylib,至少暫時使用這種方法。 如果它們耦合得足夠緊密,需要共同開發,也許它應該是永久合並?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM