How can I tell a Cursive Clojure module to depend on a local Java/Scala module?

1.9k Views Asked by At

I imported a Leiningen project into Intellij to sit alongside some existing Java & Scala modules. I would like to call functions from those modules from my Clojure module, but I'm not sure how to define this dependency. I went to Project Settings -> Modules and the "Dependencies" tab that's usually there is missing, leading me to believe that I'm not allowed to express dependencies anywhere other than the Leiningen project file (I've played with the Leiningen project editor and can't figure out how to do this there either...).

Here is the .iml file if anyone is curious how Intellij is viewing this module.

<?xml version="1.0" encoding="UTF-8"?>
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="testproject:0.1.0-SNAPSHOT" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
  <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
  <excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.3" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.6.0" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/tools.nrepl:0.2.10" level="project" />

2

There are 2 best solutions below

0
On BEST ANSWER

So, I eventually was able to do this... as dAni suggested, I was able to create a new Clojure project (through IntelliJ this time -- previously I did "lein new clj-test" then tried to import this into IntelliJ), create a Leiningen build file, process that build file, and then see the Dependencies tab for the module in Project Structure.

Still, the REPL could not find the classes. So I had to edit the Run configuration to use nREPL in "a normal JVM process" which let me select the module whose classpath I would presumably be using.

Run config for normal JVM process nREPL

Hate to be the guy to accept my own answer (especially since this has some limitation... I want to use this with Gorilla REPL in the end so will probably devise a different strategy for that) but I think this answers the original question pretty well, hope it helps someone. I think essentially what the above strategy is doing is using Leiningen for dependency resolution but not actually for the REPL, so Leiningen's dependencies are available on the classpath but the REPL is launched some other way via IntelliJ.

1
On

I develop Cursive. I suspect there may not be a good solution for this right now. I'll look at the code and see if I can figure out a way to do it, but it'll require knowledge of how Maven, Gradle or SBT (in your case) represent the modules internally. I'll try to look at this today and let you know. I actually don't know if it's possible in IntelliJ for a Maven project to depend on an SBT project, for example, or a Gradle one.

In the meantime, publishing to your local repo is the only workaround I can think of. Sorry, I know it's clunky.

There's no difference from IntelliJ's point of view between a "normal" project and an IntelliJ one, it's just that Cursive will rewrite a lot of the module configuration on each sync since in theory that configuration should be managed by Leiningen. This is more or less how the Maven integration works.