Fork me on GitHub
#tools-deps
<
2019-07-13
>
yuhan18:07:53

Is it possible to mix Java source files in a deps.edn project?

andy.fingerhut18:07:43

I believe the answer is that you can have Java source files, but deps.edn isn't intended to do anything with them.

yuhan18:07:51

so I just put them in the src/ folder and they'll get picked up by an (import) statement?

andy.fingerhut18:07:11

Something (other than the clj or clojure commands) is welcome to compile Java source files to .class and/or .jar files that can be on a classpath directory specified in a deps.edn file, but having such source files around does not cause clj or clojure commands to compile them.

andy.fingerhut18:07:24

You should use some other tool to cause Java source files to be compiled.

yuhan18:07:13

oh I see, that clears things up - so I'll need to compile a .jar file and refer to it using a :local/root dep

andy.fingerhut18:07:41

That is one way, yes.

yuhan18:07:38

hmm, I guess that's what Lein is doing with its :java-source-paths key

yuhan18:07:23

Just to confirm, does that work with interactive development - if I recompile the jar and refresh the clojure ns in the REPL, will the updated classes be imported?

andy.fingerhut18:07:10

I have not tried, but I would guess no, with the default choice of JVM class loaders used by Clojure. Maybe there is a way using non-default classloaders to make something like that happen, but I have never done it, and I could be wrong in guessing that it is even possible. You would likely be asking for additional headaches by attempting to do so.

andy.fingerhut18:07:24

If you like the idea of diving in and seeing if you can make it work, this StackOverflow was an early hit I found for Google search terms: "java reload class from jar" https://stackoverflow.com/questions/728140/can-i-dynamically-unload-and-reload-other-versions-of-the-same-jar

andy.fingerhut18:07:18

But I would strongly caution you that without more expert help than me (or perhaps you have already done similar things before), you could be in for a lot of confusing debugging and frustration there.

yuhan18:07:36

Thanks for the advice - I'll probably hold off on doing anything like that then, having little experience with JVM side of things