I have a Leiningen project that is compiling both Java and Clojure files. The Java files import some of the classes that are generated from the Clojure files (with gen-class).
When I do lein compile, I get compilation errors on the imports in the Java files (saying it can’t find the classes). If I remove the Java files from the project, do lein compile, add the Java files back, and do lein compile again, everything works fine.
So, it’s like the Clojure files need to be compiled before the Java files.
By the way, I am including the Clojure files that gen classes in the :aot list.
What is going wrong here?
(The code in this answer is untested, although it should hopefully work with Leiningen 1.x (for recent values of x).)
Leiningen’s
compiletask runs thejavactask automatically if yourproject.cljspecifies a:java-source-path. It does so prior to compiling Clojure sources, because I suppose that’s the usual direction of the dependency.To get around this, you could use a hook:
Place this somewhere on your build-time classpath and add
to your project map.
Note that
javac, when called directly, will still not callcompile. You could also make it equivalent tocompilee.g. by hooking it with the following function:The last form of
compile-clj-first-hookwould then need to be(Making
compilenot calljavacat all would probably breakjar/uberjar.)