Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure CLI by
retagged by

When I need to run two or more instances of clojure in the same project (with different parameters), they end up racing for the same cache folder that is created in the same directory. The error we see in such cases is Could not find or load main class clojure.main. Sometimes there are other errors.

If I understand the script logic correctly, it chooses the current directory for the cache and it uses has of a combination of parameters as unique identifier but in my case the resulting folder is the same.

# Determine whether to use user or project cache
if [[ -f deps.edn ]]; then
  cache_dir=.cpcache
else
  cache_dir="$user_cache_dir"
fi

Would be great to either introduce a locking mechanism that prevents racing situations or as a workaround provide an option to specify the extra argument for the cache dir or the checksum used.

Possible solution:

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"

1 Answer

0 votes
by

There's issue TDEPS-119 on Jira that's about a different thing a solution to which will likely resolve your issue as well.

by
There is a comment on that issue that I have an answer for:

> Stanislav Yurin
> February 26, 2019 at 12:33 AM

> Sorry, can't find the repository source of that bash script anywhere, so not attaching a patch file.

Here is a link to repository: https://github.com/clojure/brew-install/blob/1.11.1/src/main/resources/clojure/install/clojure

Unfortunately I can't comment on the issue itself.
...