I am using Clojure's java-time
library, which is wrapper of java.time
[1].
My program works when I invoke lein run
or when I call the functions through the repl. On the other hand when I try to do lein uberjar
I get the following error with the classes involved:
$ lein uberjar
Compiling foo.cli
Compiling foo.core
Compiling foo.holidays
nil
Syntax error (ClassCastException) compiling at (/tmp/form-init8528909580728167374.clj:1:73).
class java_time.graph.Types cannot be cast to class java_time.graph.Types (java_time.graph.Types is in unnamed module of loader 'app'; java_time.graph.Types is in unnamed module of loader clojure.lang.DynamicClassLoader @141c66db)
Full report at:
/tmp/clojure-6795557396101417445.edn
Compilation failed: Subprocess failed
I have isolated which expression causes this problem and it happens to be:
(java-time/minus (java-time/local-date) (java-time/period 2 :days))
I am not sure why it is failing and the error is quite cryptic. My bet is that the compiler gets confused casting some classes when generating the uberjar but it surprises me that the repl works fine. Is it related to the :aot
used for the uberjar creation?
This is a snippet of the project.clj
file concerning that:
(defproject foo
...
:main ^:skip-aot foo.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
.edn
created by the compiler that is not in the error message...org.apache.poi
library to write excel files. And that works fine! I am only having this issues with thejava.time
wrapperjava-time
, with theplus
andminus
functions...(some-> 1614703906000 instant)
(but not with(-> 1614703906000 instant)
and again it only happens with the direct-linking flag. It seems like the same problem, but I don't get your problem withminus
. curiouser and curiouser