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

+1 vote
in Clojure by
closed by

Java has a way to quickly find out the version from the command line:
java -version

Is there something similar for the cli and clojure commands? If not, it would be helpful if these commands had something similar, preferably printing out both Clojure version and Java version, so a user can quickly determine what is installed and running.

closed with the note: Released in Clojure CLI 1.10.2.790

2 Answers

+1 vote
by
selected by
 
Best answer

Clojure CLI 1.10.2.790 now has -version and --version options (same meaning as Java).

This reports the Clojure CLI version. It does not report the Java version - use java to do that.

by
Nice! Thanks, Alex.
0 votes
by

"Clojure" here is over-loaded (and I'm not actually even sure which you're asking for) - there is both the Clojure command-line tool and the version of the Clojure language jar that you are currently using. They are independent and any version of the tool can be used with any version of Clojure (ie the Clojure 1.10.2.774 tool can be using Clojure 1.0, or Clojure 1.9.x tool can be using Clojure 1.10.2).

You can see the version of the tool with either clj -h (first line) or clj -Sdescribe.

You can see the version of Clojure you're currently using with clj -M -e "*clojure-version*".

Because of the confusion of exactly what to do, I have not yet decided what to do for this. :)

by
I guess I can throw further confusion on the fire by saying that the Clojure tool may run two processes - the first to compute classpaths which will use a version of Clojure that matches the tool prefix version and the second is whatever program you're running which is whatever you say to use.
by
Ah, gotcha. I was specifically thinking of reporting the Clojure version (e.g., 1.10.2.774), not specifically the `clojure` command-line tool, though I thought that these two were (at least semi-)linked together. I guess what I'm asking for is something that will answer, as easily as possible "What am I running?" And yes, I realized that I could do `cli -M -e "*clojure-version*"`, but that's pretty long-winded. It seems like a command line tool should just have a `--version` option.
by
You can also get the JVM version via system properties:

$ clojure -M -e '(println "Java" (System/getProperty "java.version") "Clojure" (clojure-version))'
Java 15 Clojure 1.10.2

Evaluating (System/getProperties) will return a hash map full of interesting information about the environment your program is running under.
by
"I guess I can throw further confusion on the fire by saying that the Clojure tool may run two processes - the first to compute classpaths which will use a version of Clojure that matches the tool prefix version and the second is whatever program you're running which is whatever you say to use."

OK, good point.
by
@sean, yep, I know all that exists and I'm not suggesting that there is no version information available. It's all there somewhere. I was just looking for something that would spit it out conveniently, without wordy incantations.
by
"I was specifically thinking of reporting the Clojure version (e.g., 1.10.2.774), not specifically the `clojure` command-line tool" -- 1.10.2.774 is the version of the CLI, not Clojure.

clj -h shows the CLI version as the first line (or clojure -h).

But the Clojure version is set in your project's deps.edn file or in your user deps.edn file or else it defaults to the system deps.edn file.

The clj/clojure commands can run any Clojure (language) version -- I have aliases in my user deps.edn file for everything from Clojure 1.0 all the way up to Clojure 1.10.2 (and also "master" which is now Clojure 1.11).

Does that help? Or does it further confuse?
by
Dave Roberts wrote: "I was specifically thinking of reporting the Clojure version (e.g., 1.10.2.774), not specifically the `clojure` command-line tool, though I thought that these two were (at least semi-)linked together."

Note that 1.10.2.774 _is_ a version number of the `clojure` command-line tool.  Clojure the language has no such version number.  Clojure the language on the JVM has version numbes like 1.9.0, 1.10.0, 1.10.2, etc. but not 1.10.2.774.
...