2016-10-14 42 views
0

我想在我的項目中使用CIDER的調試器,這是在maven中設置的(無法切換到Leiningen)。我已配置的Clojure,Maven的插件作爲在他們的github自述說:Nrepl中間件未正確加載Maven項目

<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快照。

有了這個配置,我啓動使用

$ mvn clojure:nrepl 

而與此,我能夠從使用emacs的cider-connect連接的nREPL服務器。

有了這個設置,我可以做很多事情,比如加載命名空間和使用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) 

注意,使用leiningen與cider-jack-in當依賴正確的nREPL注入,我能夠使用調試器。如果我將cider-connect用於lein repl,我會遇到同樣的問題,但我從來沒有配置leiningen來加載nREPL中間件。這使我相信中間件在maven案例中也沒有被初始化(雖然被指定)。

我在配置中缺少什麼來完成這項工作?

回答

1

,我發現自己的答案Clojure中,Maven的插件的問題跟蹤:https://github.com/talios/clojure-maven-plugin/pull/87

看來這不是通過增加nreplMiddlewares配置不夠,你還需要在開始nrepl服務器時通過nrepl處理程序。我這樣做:

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

有了這個,現在蘋果酒的作品就像預期的一樣,我可以使用調試器。

+0

您可以在您的pom.xml文件的頂級'properties'元素中爲'clojure.nrepl.handler'添加一個值,而不是在每次調用時都通過'-D'來傳遞它。 – semperos