Fork me on GitHub
#tools-deps
<
2020-04-12
>
afhammad11:04:53

Hi, having issues importing java classes (generated by protobuf) from another folder in the monorepo using deps.edn . I've tried both adding the paths to :paths of my project and creating a deps.edn in the protos folder and adding that as a local dep. In both cases the classpath shows up when doing clj -Spath but starting a repl fails with ClassNotFoundException

practicalli-johnny12:04:30

@afhammad have you tried {:local/root "/path/to/java/classes"} ? I used this to import java sources into a deps.edn project, using an alias, e.g. https://github.com/practicalli/clojure-deps-edn/blob/master/deps.edn#L63 Perhaps that will work for classes too, as it add them onto the classpath.

afhammad13:04:17

@jr0cket does it have to be a zip? It's currently a folder with .java files. This worked using boot's :source-paths https://github.com/boot-clj/boot/wiki/Boot-Environment#env-keys

Alex Miller (Clojure team)13:04:43

If you have Java files, you need to javac compile them into classes

Alex Miller (Clojure team)13:04:50

If you have classes, what you say above should work, but make sure the classes are in a directory structure that matches their package name (just like Clojure source)

afhammad19:04:54

Thanks @alexmiller. Precompiling worked. Is there a nice way of doing it as part of the deps.edn setup? One reason is it requires passing in a .jar dependency in order to compile which is already a dep of the project, but having the javac compilation as a separate step means I have to worry about fetching that dependency myself.

Alex Miller (Clojure team)19:04:57

it will always be an extra step, but there are some helper dep tools out there to do that

Alex Miller (Clojure team)19:04:29

one option is to portion the java stuff into its own project that you can build (with mvn or something else), deploy it, and depend on it

afhammad19:04:30

yeh, thats one way to go, thanks