cljfx

Jonathan Bennett 2024-10-30T07:17:11.906379Z

I'm trying to transition from lein to the clojure tools because I like Practicalli's repl setup. I got everything working (I think) except building the uberjar via Github actions. Here's my deps.edn

{:paths ["src" "resources"]
 :deps
 {org.clojure/clojure {:mvn/version "1.11.1"}
  org.clojure/core.cache {:mvn/version "1.0.225"}
  com.brunobonacci/mulog {:mvn/version "0.9.0"}
  metosin/malli {:mvn/version "0.16.2"}
  io.github.cljfx/dev {:mvn/version "1.0.39"}
  cljfx/cljfx {:mvn/version "1.9.3"}
  clojure-csv/clojure-csv {:mvn/version "2.0.1"}}
 :aliases
 {;; Run with clj -T:build function-in-build
  :run {:main-opts ["-m" "megastrike.core"]}
  :build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.5" :git/sha "2a21b7a"}}
          :ns-default build
          :jvm-opts ["-Dcljfx.skip-javafx-initialization=true"]}}}

Jonathan Bennett 2024-10-30T07:17:38.357599Z

Here's build.clj

(ns build
  (:require [clojure.tools.build.api :as b]))

(def class-dir "target/classes")
(def uber-file (format "target/megastrike.jar"))

;; delay to defer side effects (artifact downloads)
(def basis (delay (b/create-basis {:project "deps.edn"})))

(defn clean [_]
  (b/delete {:path "target"}))

(defn uber [_]
  (clean nil)
  (b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
  (b/compile-clj {:basis @basis
                  :ns-compile '[megastrike.core]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :basis @basis
           :main 'megastrike.core}))

Jonathan Bennett 2024-10-30T07:18:43.151579Z

I got this error on github:

Execution error (UnsupportedOperationException) at com.sun.glass.ui.gtk.GtkApplication/lambda$new$5 (GtkApplication.java:164).
Unable to open DISPLAY
I think that the skip-javafx-initialization=true setting didn't get set. Am I passing it wrong?

vlaaad 2024-10-30T11:17:02.228799Z

Can you share the whole stack trace?

vlaaad 2024-10-30T11:39:43.391609Z

That doesn't have the whole stack trace either unfortunately

vlaaad 2024-10-30T11:40:46.230459Z

I think there is a special jvm property that can be set to print the whole stack trace to output instead of writing it to file

vlaaad 2024-10-30T11:43:16.917159Z

-Dclojure.main.report=stderr

Jonathan Bennett 2024-10-30T11:44:18.546659Z

Ok, running it again with that option

Jonathan Bennett 2024-10-30T11:46:17.834279Z

The only differences I see between my deps.edn build and my project.clj build has to do with aot. But I can't figure out how to do that in the documentation

Jonathan Bennett 2024-10-30T11:48:19.031009Z

Specifically: I have the kv-pair :main ^:skip-aot megastrike.core in my project.clj file and don't know how to add that to deps.edn and the uberjar profile has the kv-pair :aot :all , which I also don't know how to replicate.

vlaaad 2024-10-30T12:05:36.601169Z

damn, that error doesn’t say much, and only hides the real error

vlaaad 2024-10-30T12:07:53.696769Z

it seems that compile-clj launches another jvm to compile your code

Jonathan Bennett 2024-10-30T12:09:13.744439Z

and that jvm isn't getting the skip-initialization option

vlaaad 2024-10-30T12:09:30.772349Z

yeah

vlaaad 2024-10-30T12:09:55.817549Z

you probably want to add :java-opts here that makes cljfx skip javafx initialization

vlaaad 2024-10-30T12:18:45.613149Z

Please re-read what I suggested

Jonathan Bennett 2024-10-30T13:02:31.405069Z

Ok, I found it. I'm not quite sure what the underlying cause is, but setting in-development? to false fixes it.

Jonathan Bennett 2024-10-30T13:05:24.901629Z

I suspect it's some interaction between the headless nature of Github action runners and what cljfx/dev expects to see. But it's irrelevant because I shouldn't be shipping in development anyway.