当我需要在同一项目中同时运行两个或更多 clojure 实例(具有不同的参数)时,它们最终会为了在相同目录中创建的同一缓存文件夹而竞争。在这种情况下我们会看到的错误是 找不到或加载主类 clojure.main
。有时还会有其他错误。
如果我对脚本逻辑的理解正确,它选择当前目录作为缓存,并且使用参数组合的哈希值作为唯一标识符,但在我的情况下,最终的文件夹是相同的。
# Determine whether to use user or project cache
if [[ -f deps.edn ]]; then
cache_dir=.cpcache
else
cache_dir="$user_cache_dir"
fi
最好引入一种锁定机制,防止竞争情况,或者作为解决方案,提供一种指定缓存目录额外参数或校验和的选项。
可能的解决方案
diff --git a/src/main/resources/clojure/install/clojure b/src/main/resources/clojure/install/clojure
index 67272b7..53fd7ec 100755
--- a/src/main/resources/clojure/install/clojure
+++ b/src/main/resources/clojure/install/clojure
@@ -22,6 +22,7 @@ jvm_opts=()
resolve_aliases=()
classpath_aliases=()
repl_aliases=()
+cache_extra=
mode="repl"
while [ $# -gt 0 ]
do
@@ -108,6 +109,11 @@ do
deps_data="${1}"
shift
;;
+ -Scache)
+ shift
+ cache_extra="${1}"
+ shift
+ ;;
-Scp)
shift
force_cp="${1}"
@@ -197,7 +203,7 @@ if "$help"; then
on the JVM, e.g. to start a REPL or invoke a specific function with data.
The Clojure tools will configure the JVM process by defining a classpath
(of desired libraries), an execution environment (JVM options) and
- specifying a main class and args.
+ specifying a main class and args.
Using a deps.edn file (or files), you tell Clojure where your source code
resides and what libraries you need. Clojure will then calculate the full
@@ -234,6 +240,7 @@ if "$help"; then
-Spath Compute classpath and echo to stdout only
-Spom Generate (or update) pom.xml with deps and paths
-Stree Print dependency tree
+ -Scache CACHE Provide arbitrary data to include into cache hash
-Scp CP Do NOT compute or cache classpath, use this one instead
-Srepro Ignore the ~/.clojure/deps.edn config file
-Sforce Force recomputation of the classpath (don't use the cache)
@@ -320,7 +327,7 @@ else
fi
# Construct location of cached classpath file
-val="$(join '' ${resolve_aliases[@]})|$(join '' ${classpath_aliases[@]})|$(join '' ${repl_aliases[@]})|$exec_aliases|$main_aliases|$deps_data|$tool_name|$tool_aliases"
+val="${cache_extra}|$(join '' ${resolve_aliases[@]})|$(join '' ${classpath_aliases[@]})|$(join '' ${repl_aliases[@]})|$exec_aliases|$main_aliases|$deps_data|$tool_name|$tool_aliases"
for config_path in "${config_paths[@]}"; do
if [[ -f "$config_path" ]]; then
val="$val|$config_path"