This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-29
Channels
- # adventofcode (9)
- # announcements (2)
- # aws (78)
- # babashka (55)
- # beginners (97)
- # biff (9)
- # calva (11)
- # cherry (2)
- # cider (8)
- # clerk (7)
- # clj-kondo (6)
- # clj-on-windows (4)
- # clojure (213)
- # clojure-austin (6)
- # clojure-europe (63)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-spec (10)
- # clojure-uk (1)
- # clojurescript (14)
- # clr (2)
- # community-development (3)
- # conjure (14)
- # datomic (2)
- # deps-new (5)
- # dev-tooling (10)
- # editors (3)
- # emacs (3)
- # etaoin (19)
- # events (4)
- # fulcro (71)
- # holy-lambda (20)
- # java (3)
- # jobs (2)
- # leiningen (4)
- # lsp (24)
- # malli (15)
- # membrane (107)
- # music (1)
- # off-topic (29)
- # pedestal (4)
- # polylith (1)
- # portal (2)
- # rdf (5)
- # releases (7)
- # scittle (5)
- # shadow-cljs (8)
- # tools-build (15)
- # tools-deps (6)
- # xtdb (13)
The Clojure CLI respects JAVA_CMD
and JAVA_HOME
environment variables. With clojure.tools.build/java-command
, if you don't specify :java-cmd
, it defaults to java
and picks up whatever your system default is (even tho' those env vars are passed into the process
when you run it). This means that you can't just set JAVA_CMD
and have your Clojure build consistently use it, you potentially need to replicate some sort of "find java
" logic in every build.clj
file that runs Java/Clojure subprocesses. Would it make sense for the default behavior of java-command
-- when :java-cmd
is not specified -- to attempt to mimic the "find java
" logic of the Clojure CLI for consistency?
More in 🧵
(~/clojure)-(!2009)-> java -version
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment (build 17.0.4+8-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.4+8-Ubuntu-120.04, mixed mode, sharing)
Tue Nov 29 09:30:29
(~/clojure)-(!2010)-> echo $JAVA_CMD
/Developer/jdk-19+36/bin/java
Tue Nov 29 09:30:46
(~/clojure)-(!2011)-> clj -Sdeps '{:deps {io.github.clojure/tools.build {:git/tag "v0.8.5" :git/sha "9c738da"}}}'
Clojure 1.11.1
user=> (require '[clojure.tools.build.api :refer :all])
nil
user=> (System/getenv "JAVA_CMD")
"/Developer/jdk-19+36/bin/java"
user=> (System/getProperty "java.version")
"19"
user=> (java-command {:main 'clojure.main :basis (create-basis) :main-args ["-e" "[(System/getenv \"JAVA_CMD\") (System/getProperty \"java.version\")]"]})
{:command-args ["java" "-cp" "src:/home/sean/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:/home/sean/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar:/home/sean/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar" "clojure.main" "-e" "[(System/getenv \"JAVA_CMD\") (System/getProperty \"java.version\")]"]}
user=> (process *1)
["/Developer/jdk-19+36/bin/java" "17.0.4"]
{:exit 0}
user=>
I tripped over this writing an external test runner for Polylith (which runs in a subprocess instead of using classloader isolation) and realized it was picking up the system default java
so I added "find java
" logic based on those env vars to fix it.
Then I noticed various subprocesses in our build.clj
were also picking up the system default java
even tho' they were using java-command
and so they were running with JDK 17 instead of JDK 19 (which the top-level build stuff was using since JAVA_CMD
was set).
I think there's a jira for this, haven't gotten to it yet
That's just for compile-clj
well feel free to expand its scope in the jira
OK, wanted to check you were amenable to that.
yes, compile-clj relies on java-command so the more generic fix here would cover both
I left the title of TBUILD-34 as-is but added a comment suggesting a expansion of scope.
I had missed that my patch for TDEPS-184 needed additional work, sorry. I don't think I got an email about your comment (or it went into spam).
(I responded with some questions about approach)
I updated my build-clj
wrapper to do this defaulting since we needed it at work. Once there's an official solution in tools.build
, I can remove it from build-clj
(and also update my Polylith external test runner and part of our build.clj
file at work -- our exec-command
-- to match). Thanks!
io.github.seancorfield/build-clj {:git/tag "v0.8.5" :git/sha "de693d0"} -- Common tools.build
tasks abstracted into a library, building on the examples in the https://clojure.org/guides/tools_build`tools.build`https://clojure.org/guides/tools_build:
• Modify calls to compile-clj
and java-command
to default :java-cmd
based on the JAVA_CMD
and/or JAVA_HOME
environment variables, if set. This won't be necessary when https://clojure.atlassian.net/browse/TBUILD-34 is addressed.
• Update tools.build
to v0.8.5 (for the snapshot/maven policy stuff in t.d.a.).