Leiningen compilation order?

江枫思渺然 提交于 2019-12-19 19:14:43

问题


I'm just learning how to lein, and I'd like to use from a Java source a class created by deftype in a Clojure source. This wasn't covered in the basic tutorial and I can't get it to work properly.

The problem is that Java source can't import Clojure class, since it hasn't been compiled yet. And Clojure class isn't compiled, since compilation is aborted by the Java source.

I give a minimal example:

  1. Create a new project with:

    lein new app javafoo
    
  2. Add to project.clj

    :aot :all
    :java-source-paths ["src/java"]
    
  3. Put into src/javafoo/core.clj:

    (ns javafoo.core)
    (deftype PPoint [x y])
    
  4. Put into src/java/JavaFoo.java:

    package foo.java;
    import javafoo.core.PPoint;
    
    public class JavaFoo {
        public static void main(String[] args) {
            System.out.println("JavaFoo");
        }
    }
    
  5. Try to compile

    lein compile
    

It fails with package javafoo.core doesn't exist. So now I have to

  1. Comment out :java-source-paths
  2. Compile
  3. Uncomment :java-source-paths
  4. Compile

It finally works. Is there a way to make it work from the start?


回答1:


Add this line to your project.clj:

:prep-tasks [["compile" "javafoo.core"] "javac"]


来源:https://stackoverflow.com/questions/19157491/leiningen-compilation-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!