3

I'm having troubles compiling a mixture of clojure and java files into a single package. The files have dependencies between each other and if they were all just java files the java compiler could handle all of this. Just to make this concrete I want to create a package called pkg with 4 files, A.java, b.clj, c.clj, and D.java. A.java contains main and creates an object declared in b.clj, b.clj calls functions in c.clj and uses objects of class D. How do I write the project file?

If I use

 :prep-tasks ["javac" "compile"]

in the project file then I get a complaint while compiling A.java that something in pkg.b or pkg.c is undefined. If I use

 :prep-tasks ["compile" "javac"]

I get a complaint that class pkg.D does not exist. If I try

 :prep-tasks [["javac" "pkg/D.java"] "compile" "javac"]

it can't find pkg/D.java, even though I set java-source-paths correctly.

One way to handle this would be to create 3 packages, one that contains A.java, one that contains b.clj and c.clj, and one that contains D.java. Then build a jar for D.java, a jar for b and c, that uses D.jar, and a jar for A that uses bc.jar and D.jar. Ugly, though.

1 Answer 1

0

You cannot have circular dependencies between the java and clojure sources in a single lein project. As you correctly point out, you could split the project in more than one package to avoid the circular dependency, but you don't need 3 packages but just 2, as lein supports Clojure -> Java dependencies. So you could have a project with b, c and D and another one with just A.

Another option would be just to write A in Clojure so you avoid the burden of multiple projects.

Sign up to request clarification or add additional context in comments.

1 Comment

I pulled it apart into 3 packages. Once the dependencies are handled it's just as easy to make 3 instead of 2. A makefile is needed anyway. I didn't want to rewrite it as A is really the gui and D is the data. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.