tools-deps

Rachel Westmacott 2024-01-04T15:11:53.950679Z

I have two commands and two questions. JDK_JAVA_OPTIONS=-Dclojure.server.repl="'{:address,\"0.0.0.0\",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}'" clj -M -e '(println "hi")' and JDK_JAVA_OPTIONS=-Dclojure.server.repl="'{:address,\"0.0.0.0\",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}'" clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.12.0-alpha1"}}}' -M -e '(println "hi")' My questions are: "Why does the command that specifies a Clojure version not print 'hi'?" and "Why does the one that specifies Clojure 12 start a Clojure 11 socket repl?" If anyone is able to enlighten me in any regard I should be most grateful.

Rachel Westmacott 2024-01-04T15:13:54.908589Z

(apologies if this is the wrong channel - it's hard to know where exactly the issue lies as I don't yet understand it)

Alex Miller (Clojure team) 2024-01-04T15:25:34.725379Z

The Clojure CLI potentially runs 2 jvms - the first (optional) one will be run to calculate the classpath based on your deps.edn config. The results of that are cached (in .cpcache), so this will not always happen. The CLI then runs your actual program in the second jvm. The JDK_JAVA_OPTIONS environment variable is applied to ALL jvms, so you are actually running the socket repl from the first classpath-computing jvm - that one is an uberjar that bundles its own version of Clojure (1.11.1).

1
Alex Miller (Clojure team) 2024-01-04T15:27:38.380389Z

if you want to supply the env vars ONLY to the latter (user) jvm, there is an https://clojure.org/reference/deps_and_cli#env_vars for that: JAVA_OPTS (and if you only want to supply to the classpath-computing jvm, there is an env var for that: CLJ_JVM_OPTS )

1
Alex Miller (Clojure team) 2024-01-04T15:29:26.105749Z

you can also use -J to pass env vars on the clj command line without using any env vars

1
Rachel Westmacott 2024-01-04T15:29:50.312099Z

Thank you very much. This is all very helpful.

Rachel Westmacott 2024-01-04T15:29:57.351309Z

(and interesting)

Alex Miller (Clojure team) 2024-01-04T15:29:59.480279Z

example here: https://clojure.org/guides/deps_and_cli#socket_repl

Alex Miller (Clojure team) 2024-01-04T15:30:20.482449Z

oh, that's actually yet another way to do it :)

Alex Miller (Clojure team) 2024-01-04T15:36:28.750479Z

but with -J you would do something like:

clj '-J-Dclojure.server.repl={:address,"0.0.0.0",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}' -M -e '(println "hi")'

👍 1
Rachel Westmacott 2024-01-04T15:39:03.123159Z

I notice that the quoting rules seem to be different for JAVA_OPTS compared to JDK_JAVA_OPTIONS - I assume that's because there's an extra hop in the chain as it gets passed through to the user process.

Rachel Westmacott 2024-01-04T15:40:16.842039Z

Thank you! I now have Clojure 12 running in my server repl.

🎉 1
Alex Miller (Clojure team) 2024-01-04T16:44:21.565749Z

I would expect the quoting to be the same for the two env vars (but different for -J)

Rachel Westmacott 2024-01-04T16:45:17.408399Z

hmm, empirically it didn't seem to be. I swapped out the one for the other in my command and it didn't behave as I had previously expected

Rachel Westmacott 2024-01-04T16:47:14.464889Z

this does something JDK_JAVA_OPTIONS=-Dclojure.server.repl="'{:address,\"0.0.0.0\",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}'" clj -M -e '(println "hi")' whereas this JAVA_OPTS=-Dclojure.server.repl="'{:address,\"0.0.0.0\",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}'" clj -M -e '(println "hi")' throws an exception ("java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol")

Rachel Westmacott 2024-01-04T16:47:39.877699Z

I think the only change I have there is the env var name.

Alex Miller (Clojure team) 2024-01-04T16:54:50.836939Z

I don't think that quoting is correct in either case, but not sure why they would differ in behavior. the single quote inside the double quote does not seem right to me - seems like that should make it through to the system property edn reading and act as map quoting (in which case the trailing single quote is probably ignored). And I'm not sure the \" is correct in shell?

Rachel Westmacott 2024-01-04T16:55:57.237489Z

I'm absolutely delighted to be schooled in this - I only have what I have through trial and error - I do not know what I am doing when it comes to shells and escaping.

Alex Miller (Clojure team) 2024-01-04T16:56:21.721639Z

I guess the former is handled by the jdk directly and the latter is passed on by the clj script so they are different

Alex Miller (Clojure team) 2024-01-04T16:56:52.350899Z

in fact, I think the clojure script may be missing double quotes where that happens

Rachel Westmacott 2024-01-04T16:58:32.165569Z

I had quite a bit of trouble getting it to retain any double quotes around the :address, so it kept trying to parse it as a number (and failing). What I ended up with was the first thing I found that worked.

Alex Miller (Clojure team) 2024-01-04T17:00:29.933749Z

I think you need the \" but should remove the inner ' '

Rachel Westmacott 2024-01-04T17:02:25.274229Z

For JAVA_OPTS that's what I've ended up with. When using JDK_JAVA_OPTIONS (which I no longer need) it seems I needed the extra quotes.

Alex Miller (Clojure team) 2024-01-04T17:02:37.099779Z

I don't think so

Alex Miller (Clojure team) 2024-01-04T17:04:01.405939Z

that's not something the shell would use and the clojure code reading that property could at best treat that as a quoted data structure, which is not needed

Rachel Westmacott 2024-01-04T17:04:57.465989Z

JDK_JAVA_OPTIONS=-Dclojure.server.repl="{:address,\"0.0.0.0\",:port,5555,:accept,clojure.core.server/repl,:server-daemon,false,:client-daemon,false}" clj -M -e '(println "hi")' gives me a stacktrace ("Invalid number: 0.0.0.0")- perhaps I've misunderstood something

Alex Miller (Clojure team) 2024-01-04T17:05:35.877499Z

that works for me

⁉️ 1
Alex Miller (Clojure team) 2024-01-04T17:06:11.445989Z

(separately, the clj script is missing quotes for passing $JAVA_OPTS, but that's irrelevant in these particular examples)

Alex Miller (Clojure team) 2024-01-04T17:06:58.699389Z

at this point it may become relevant what you have for java -version and clj --version

Rachel Westmacott 2024-01-04T17:09:01.507769Z

/bin/bash on Ubuntu | openjdk 17.0.9 | Clojure 1.11.1.1165 if you're interested, but we may be getting into diminishing returns at this point - I already feel like I've used a lot of your time.

Alex Miller (Clojure team) 2024-01-04T17:11:35.659559Z

the latter is https://clojure.org/releases/tools, might want to install latest (1.11.1.1435), might have fixed something there since

Alex Miller (Clojure team) 2024-01-04T17:14:03.455089Z

the specific shell you're using may also affect this

Rachel Westmacott 2024-01-04T17:14:42.485729Z

I updated Clojure to 1435, no change.

Rachel Westmacott 2024-01-04T17:16:02.926459Z

I don't think I've done anything strange to my shell, it should be fairly vanilla. But I'm running Ubuntu rather than Mac...?

Alex Miller (Clojure team) 2024-01-04T17:16:06.968639Z

well, may be my environment, I see different things in different directories

Alex Miller (Clojure team) 2024-01-04T17:20:25.771579Z

there must be some difference here in how the jvm treats JDK_JAVA_OPTIONS

Alex Miller (Clojure team) 2024-01-04T17:21:39.908569Z

also relevant is that depending on whether you have a cached classpath, you may be running from either the first uberjar classpath jvm or the second repl jvm, so you get different behavior on first or nth invocation

Alex Miller (Clojure team) 2024-01-04T17:22:02.542499Z

so, definitely shouldn't use JDK_JAVA_OPTIONS regardless

1
1