I tried making a minimal project I could compile with graalvm, but I am having issues getting native-image to build. Getting reflection warnings, despite it being a pretty minimal file. I am runnin native-image -jar ./target/standalone.jar --features=clj_easy.graal_build_time.InitClojureClasses
Here is my file.
(ns main
;; any :require and/or :import clauses
(:gen-class))
(set! *warn-on-reflection* true)
(defn do-stuff [] (println "Woah"))
(defn -main [& args]
(do-stuff))
And deps
{:paths ["src"]
:deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
:aliases
{:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.3"}}
:ns-default build}}}Two things I might try:
• your main namespace is single segment (ie. no . in the name) and I seem to remember that graal-build-time use to not work with those. It might have been fixed, but I would try changing the main namespace to something like my.main
• It doesn't look like your native-image invocation specifies a main class. It should probably be something like my.main if you update your main namespace.
Your first suggestion worked!
Its probably worth seeing if there’s an appropriate place in the docs to mention that if it’s not already addressed somewhere.
@sdata374 do you have an example error message? It would be useful to include in the docs in case someone else runs into the same issue and is searching for a fix.
Is it something like:
java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpathIt was a bunch of reflection warnings like these.
Warning: Reflection method java.lang.Class.getMethod invoked at clojure.lang.Reflector.tryFindMethod(Reflector.java:75)And then making a fallback.
Warning: Aborting stand-alone image build due to reflection use without configuration.
if I tried with --no-fallback, the generated binary didn't runOh, interesting.
I created a pull request for graal-docs at https://github.com/clj-easy/graal-docs/pull/64
Not sure if there's any particular places you checked when you hit the error, but those might be good candidates for doc improvements.
I was in the https://github.com/clj-easy/graal-build-time docs, I was unaware of this repo. But that looks like a good place to add a note
The docs do mention single segment namespaces, https://github.com/clj-easy/graal-build-time?tab=readme-ov-file#single-segment-namespaces
hmmm, the docs say it reports an error if it finds single segment namespaces, > [clj-easy/graal-build-time] WARN: Single segment namespace found for class: digest__init.class. Because this class has no package, it cannot be registered for initialization at build time.
Do you know if your setup didn't show the warning for some reason?
It did, I apologize. I didn't realize that would show at the beginning of the process which moves pretty fast on my computer
No problem. It’s an easy thing to miss. Just checking to see if it wasn’t working and we should create a bug report.