3

How do I configure my Clojure CLI deps.edn file to compile Java source files along with my .clj Clojure source files?

I found badigeon which can compile Java sources, but I'm struggling to use in my simple project.

3 Answers 3

3

You can now do that with clojure.tools.build

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

1 Comment

This page was the highest ranked answer via $SEARCH_ENGINE, but this is probably a good example, so adding it here: github.com/seancorfield/java-clojure-example/tree/master
2

Without knowing more about your context ...

The "best" way to do this currently, is to separate your Java and Clojure sources into two projects. In the Java project, create a jar with the compiled classes (using standard Java tools - perhaps make and javac) and install the jar into your local maven repo. Then add the jar file as a dependency in the deps.edn of your Clojure project.

You might also be able to use the jar directly, without installing locally, by using the local/root feature in deps.edn. See the Deps Rationale for how to do that.

Another way would be to arrange to have the Java sources compiled into a classes sub-directory of your combined (Java / Clojure) project and then add the classes directory to the :paths key in your deps.edn. The creation of the class files will (again) have to be done with Java tools or shell scripts - outside of clj.

There are some recent developments in clj that may make this easier in the future.

Comments

1

clj will not do that.

lein do a lot of things that are out-of-scope for clj command line.

You may find some library that do that, then you can call clj -m lib-that-compiles-java

Comments

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.