tools.build does not exit when requiring the Clay API
Reported by jason1903 on Slack: https://clojurians.slack.com/archives/C0BQDEJ8M/p1714087040436159
deps.edn:
{:deps {org.clojure/clojure {:mvn/version "1.12.1"} }
:aliases {:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
slipset/deps-deploy {:mvn/version "0.2.1"}
org.scicloj/clay {:mvn/version "2-beta8"}}
:ns-default build}}}
build.clj:
(ns build
(:require
[scicloj.clay.v2.api :as clay]))
(defn hello
[_opts]
(println "hello"))
Then
clojure -T:build hello
never exits.
The problem is that Clay starts a portal session to receive its client-side code.
That session should be stopped afterwards -- we will fix this in a future version.
For now, here is a workaround:
(defn hello
[_opts]
(println "hello")
(portal.api/close))
(Edit: had a typo in this code earlier, missed the important part.)
A possibly way to prevent this would be on Portal side - either add a shutdown hook that stops the server (not 100% sure this works) or get http kit updated so that clients could request the "server-loop" thread org.httpkit.server.HttpServer#serverThread be a daemon thread, which does not prevent JVM from stopping.
@daslu your suggestion did not work for me - the http-kit server kept running. I had to call (portal.runtime.jvm.launcher/stop).
Interesting.
Thanks for checking and discovering that.