4

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" />

jm0
  • 3,294
  • 2
  • 16
  • 18
  • How are the Java & Scala modules built? Are they installed in your local Maven repo? – PeakCode Feb 01 '16 at 12:55
  • I see a "dependencies" tab on my clj modules – DanLebrero Feb 01 '16 at 12:56
  • @PeakCode No, they are built using sbt but I really don't want to publish the artifacts (I've seen on some forums that people suggest using local Maven repo as you might be suggesting). I'm asking if there is a way to force the dependency purely through the IDE so I get instant re-build/resolution without configuring extra publish settings (IntelliJ has no problem building these Scala projects through IDE & I can depend on them from other Scala/Java modules without issue). – jm0 Feb 01 '16 at 16:08
  • @dAni how did you set up your project? Is it a Leiningen project? – jm0 Feb 01 '16 at 16:09
  • 1
    I opened a gradle project and then just added the lein project as a new module (File -> New -> Module from existing sources) – DanLebrero Feb 01 '16 at 16:19
  • @dAni thanks for the sanity check, I'll try fiddling with a new project. However, did you go into the project.clj & allow IntelliJ to process it as a Lein project? (There is some dropdown prompt that asks you to register it that way). My worry is that there is a difference between a default Cursive project and a Leiningen project. For example, Cursive tries to grab a lib for Clojure where as the Lein project simply gets it through dependency resolution (these dependencies can be seen by opening the Leiningen toolbar, usually on the right strip of the IDE). – jm0 Feb 01 '16 at 16:30
  • 1
    I opened it as a lein project – DanLebrero Feb 01 '16 at 17:15

2 Answers2

1

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.

Colin
  • 1,112
  • 2
  • 7
  • 16
  • Thanks Colin, let me kno! @dAni seems to think this works out of the box so I'm going to try though I'm still doubtful. I also found this question which seems to point toward the solution of building a local jar & depending on that via path through the project.clj (haven't had time to read through it fully..) -- http://stackoverflow.com/questions/2404426/leiningen-how-to-add-dependencies-for-local-jars – jm0 Feb 01 '16 at 22:06
1

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.

jm0
  • 3,294
  • 2
  • 16
  • 18