Nrepl中间件无法正确加载maven项目

时间:2016-10-14 09:17:57

标签: maven emacs clojure cider nrepl

我正在尝试在我的项目中使用CIDER的调试器,该项目是在maven中设置的(无法切换到Leiningen)。我已经配置了clojure-maven-plugin,如他们的github README中所述:

<plugin>
  <groupId>com.theoryinpractise</groupId>
  <artifactId>clojure-maven-plugin</artifactId>
  <version>1.8.1</version>
  <extensions>true</extensions>
  <executions>
    <execution>
      <id>clojure-compile</id>
      <phase>compile</phase>
      <goals>
        <goal>compile</goal>
      </goals>
    </execution>
    <execution>
      <id>clojure-test</id>
      <phase>test</phase>
      <goals>
        <goal>test</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <nreplMiddlewares>
      <middleware>cider.nrepl.middleware.apropos/wrap-apropos</middleware>
      <middleware>cider.nrepl.middleware.classpath/wrap-classpath</middleware>
      <middleware>cider.nrepl.middleware.complete/wrap-complete</middleware>
      <middleware>cider.nrepl.middleware.debug/wrap-debug</middleware>
      <middleware>cider.nrepl.middleware.format/wrap-format</middleware>
      <middleware>cider.nrepl.middleware.info/wrap-info</middleware>
      <middleware>cider.nrepl.middleware.inspect/wrap-inspect</middleware>
      <middleware>cider.nrepl.middleware.macroexpand/wrap-macroexpand</middleware>
      <middleware>cider.nrepl.middleware.ns/wrap-ns</middleware>
      <middleware>cider.nrepl.middleware.pprint/wrap-pprint</middleware>
      <middleware>cider.nrepl.middleware.pprint/wrap-pprint-fn</middleware>
      <middleware>cider.nrepl.middleware.refresh/wrap-refresh</middleware>
      <middleware>cider.nrepl.middleware.resource/wrap-resource</middleware>
      <middleware>cider.nrepl.middleware.stacktrace/wrap-stacktrace</middleware>
      <middleware>cider.nrepl.middleware.test/wrap-test</middleware>
      <middleware>cider.nrepl.middleware.trace/wrap-trace</middleware>
      <middleware>cider.nrepl.middleware.out/wrap-out</middleware>
      <middleware>cider.nrepl.middleware.undef/wrap-undef</middleware>
      <middleware>cider.nrepl.middleware.version/wrap-version</middleware>
    </nreplMiddlewares>
    <sourceDirectories>
      <sourceDirectory>src/main/clojure</sourceDirectory>
    </sourceDirectories>
    <namespaces>
      <namespace>!edu.upc.modelvsdocument.repl.*</namespace>
      <namespace>edu.upc.modelvsdocument.*</namespace>
    </namespaces>
    <!--<warnOnReflection>true</warnOnReflection>-->
  </configuration>
</plugin>

并添加了依赖项:

<dependencies>
  <dependency>
    <groupId>org.clojure</groupId>
    <artifactId>tools.nrepl</artifactId>
    <version>0.2.12</version>
  </dependency>
  <dependency>
    <groupId>cider</groupId>
    <artifactId>cider-nrepl</artifactId>
    <version>0.14.0-SNAPSHOT</version>
  </dependency>
  <!-- ... -->
</dependencies>

请注意,我的苹果酒版本正好是0.14.0-SNAPSHOT。

使用此配置,我使用

启动nREPL服务器
$ mvn clojure:nrepl

有了这个,我可以使用cider-connect从emacs连接。

通过这种设置,我可以做很多事情,比如加载命名空间和使用REPL,但是当涉及调试器等中间件功能时,我会收到有关未绑定函数或变量的各种错误。如果是调试器:

clojure.lang.LispReader$ReaderException: java.lang.IllegalStateException: Attempting to call unbound fn: #'cider.nrepl.middleware.debug/debug-reader
 at clojure.lang.LispReader.read (LispReader.java:294)
    clojure.lang.LispReader.read (LispReader.java:198)
    clojure.lang.LispReader.read (LispReader.java:187)
    clojure.core$read.invokeStatic (core.clj:3747)
    clojure.core$read.invoke (core.clj:3720)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__681$fn__684.invoke (interruptible_eval.clj:98)
    clojure.main$repl$read_eval_print__9594$fn__9595.invoke (main.clj:238)
    clojure.main$repl$read_eval_print__9594.invoke (main.clj:238)
    clojure.main$repl$fn__9603.invoke (main.clj:258)
    clojure.main$repl.invokeStatic (main.clj:258)
    clojure.main$repl.doInvoke (main.clj:174)
    clojure.lang.RestFn.invoke (RestFn.java:1523)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__681.invoke (interruptible_eval.clj:87)
    clojure.lang.AFn.applyToHelper (AFn.java:152)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invokeStatic (core.clj:657)
    clojure.core$with_bindings_STAR_.invokeStatic (core.clj:1962)
    clojure.core$with_bindings_STAR_.doInvoke (core.clj:1962)
    clojure.lang.RestFn.invoke (RestFn.java:425)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invokeStatic (interruptible_eval.clj:85)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:55)
    clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__726$fn__729.invoke (interruptible_eval.clj:222)
    clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__721.invoke (interruptible_eval.clj:190)
    clojure.lang.AFn.run (AFn.java:22)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java.lang.Thread.run (Thread.java:745)
Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'cider.nrepl.middleware.debug/debug-reader
 at clojure.lang.Var$Unbound.throwArity (Var.java:43)
    clojure.lang.AFn.invoke (AFn.java:32)
    clojure.lang.Var.invoke (Var.java:379)
    clojure.lang.LispReader$CtorReader.readTagged (LispReader.java:1351)
    clojure.lang.LispReader$CtorReader.invoke (LispReader.java:1330)
    clojure.lang.LispReader$DispatchReader.invoke (LispReader.java:786)
    clojure.lang.LispReader.read (LispReader.java:265)
    clojure.lang.LispReader.read (LispReader.java:198)
    clojure.lang.LispReader.read (LispReader.java:187)
    clojure.core$read.invokeStatic (core.clj:3747)
    clojure.core$read.invoke (core.clj:3720)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__681$fn__684.invoke (interruptible_eval.clj:98)
    clojure.main$repl$read_eval_print__9594$fn__9595.invoke (main.clj:238)
    clojure.main$repl$read_eval_print__9594.invoke (main.clj:238)
    clojure.main$repl$fn__9603.invoke (main.clj:258)
    clojure.main$repl.invokeStatic (main.clj:258)
    clojure.main$repl.doInvoke (main.clj:174)
    clojure.lang.RestFn.invoke (RestFn.java:1523)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__681.invoke (interruptible_eval.clj:87)
    clojure.lang.AFn.applyToHelper (AFn.java:152)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invokeStatic (core.clj:657)
    clojure.core$with_bindings_STAR_.invokeStatic (core.clj:1962)
    clojure.core$with_bindings_STAR_.doInvoke (core.clj:1962)
    clojure.lang.RestFn.invoke (RestFn.java:425)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invokeStatic (interruptible_eval.clj:85)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:55)
    clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__726$fn__729.invoke (interruptible_eval.clj:222)
    clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__721.invoke (interruptible_eval.clj:190)
    clojure.lang.AFn.run (AFn.java:22)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java.lang.Thread.run (Thread.java:745)

请注意,当使用带有cider-jack-in的leiningen时,nREPL会正确地注入依赖项,并且我可以使用调试器。如果我将cider-connect用于lein repl,我会遇到同样的问题,但我从未配置leiningen来加载nREPL中间件。这让我相信中间件在maven情况下也没有被初始化(虽然被指定)。

我的配置中缺少什么才能使其正常工作?

1 个答案:

答案 0 :(得分:1)

我在clojure-maven-plugin的问题跟踪器中找到了答案:https://github.com/talios/clojure-maven-plugin/pull/87

通过添加nreplMiddlewares配置似乎还不够,你仍然需要在启动nrepl服务器时传递nrepl处理程序。我是这样做的:

$ mvn clojure:nrepl -Dclojure.nrepl.handler=cider.nrepl/cider-nrepl-handler

有了这个,现在cider就像预期的那样工作,我可以使用调试器。