clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.55k stars 645 forks source link

add-lib fails when called from CIDER repl #3735

Closed filipesilva closed 3 months ago

filipesilva commented 3 months ago

Expected behavior

Clojure 1.12 add-lib (and sync-deps for that matter) works inside CIDER the same way it works inside clj.

Actual behavior

It throws in CIDER when adding the Datomic Peer dep (unsure if it happens with others).

Steps to reproduce the problem

With plain CLJ:

mkdir repro
cd repro
echo '{:paths ["src"] :deps {org.clojure/clojure {:mvn/version "1.12.0-rc1"}}}' > deps.edn
mkdir src
printf '(ns user)\n(comment\n  (sync-deps)\n\n\n  (add-lib \'com.datomic/peer {:mvn/version "1.0.7187"})\n\n\n )' > src/user.clj
clj

(NB: had to leave the extra newlines because otherwise cider-pprint-eval-defun-to-comment will comment out existing forms in the next line, but that's another issue)

then in the repl:

Clojure 1.12.0-rc1
user=> (sync-deps)
nil
user=> (add-lib 'com.datomic/peer {:mvn/version "1.0.7187"})
[com.amazonaws/aws-java-sdk-core com.amazonaws/aws-java-sdk-ec2 com.cognitect/anomalies com.cognitect/caster com.datomic/datomic-lucene-core com.datomic/io-stats com.datomic/java-io com.datomic/memcache-asg-java-client com.datomic/peer com.datomic/query-stats com.datomic/query-support com.fasterxml.jackson.core/jackson-annotations com.fasterxml.jackson.core/jackson-core com.fasterxml.jackson.core/jackson-databind com.fasterxml.jackson.dataformat/jackson-dataformat-cbor com.github.ben-manes.caffeine/caffeine com.google.errorprone/error_prone_annotations com.h2database/h2 commons-beanutils/commons-beanutils commons-codec/commons-codec commons-collections/commons-collections commons-io/commons-io commons-logging/commons-logging io.netty/netty-buffer io.netty/netty-codec io.netty/netty-codec-http io.netty/netty-codec-socks io.netty/netty-common io.netty/netty-handler io.netty/netty-handler-proxy io.netty/netty-resolver io.netty/netty-transport io.netty/netty-transport-classes-epoll io.netty/netty-transport-classes-kqueue io.netty/netty-transport-native-epoll$linux-x86_64 io.netty/netty-transport-native-kqueue$osx-x86_64 io.netty/netty-transport-native-unix-common joda-time/joda-time org.apache.activemq/artemis-commons org.apache.activemq/artemis-core-client org.apache.httpcomponents/httpclient org.apache.httpcomponents/httpcore org.apache.tomcat/tomcat-jdbc org.apache.tomcat/tomcat-juli org.checkerframework/checker-qual org.clojure/core.async org.clojure/core.cache org.clojure/core.memoize org.clojure/data.priority-map org.clojure/tools.analyzer org.clojure/tools.analyzer.jvm org.clojure/tools.cli org.codehaus.janino/commons-compiler org.codehaus.janino/commons-compiler-jdk org.fressian/fressian org.ow2.asm/asm org.slf4j/jcl-over-slf4j org.slf4j/jul-to-slf4j org.slf4j/log4j-over-slf4j org.slf4j/slf4j-api]

This seems to work fine.

But if you connect to CIDER on this project and run the forms inside src/user.clj:

(ns user)
(comment
  (sync-deps)
  ;; => [borkdude/edamame
  ;;     borkdude/sci.impl.reflector
  ;;     clj-stacktrace/clj-stacktrace
  ;;     criterium/criterium
  ;;     datascript/datascript
  ;;     fipp/fipp
  ;;     hashp/hashp
  ;;     io.github.tonsky/clj-reload
  ;;     io.github.tonsky/extend-clj
  ;;     mvxcvi/arrangement
  ;;     mvxcvi/puget
  ;;     net.cgrand/macrovich
  ;;     org.babashka/sci
  ;;     org.clojure/clojure
  ;;     org.clojure/core.rrb-vector
  ;;     org.clojure/core.specs.alpha
  ;;     org.clojure/spec.alpha
  ;;     org.clojure/tools.reader
  ;;     org.clojure/tools.trace
  ;;     persistent-sorted-set/persistent-sorted-set
  ;;     rewrite-clj/rewrite-clj
  ;;     vvvvalvalval/scope-capture
  ;;     zprint/zprint]

  (add-lib 'com.datomic/peer {:mvn/version "1.0.7187"})
  ;; => Execution error (ExceptionInfo) at clojure.tools.deps.interop/invoke-tool (interop.clj:81).
  ;;    Could not find artifact org.apache:apache:pom:8

 )

The output from sync-deps is a little bit surprising but not that much, when you think about it some more. I have some of these in ~/.clojure/deps.edn, and I guess some others come from CIDER? Not sure tbh.

;; ~/.clojure/deps.edn
{:deps {criterium/criterium         {:mvn/version "0.4.6"}
        hashp/hashp                 {:mvn/version "0.2.2"}
        vvvvalvalval/scope-capture  {:mvn/version "0.3.3"}
        org.clojure/tools.trace     {:mvn/version "0.8.0"}
        io.github.tonsky/clj-reload {:mvn/version "0.4.1"}
        datascript/datascript       {:mvn/version "1.6.5"}}}

add-lib just fails though, and it shouldn't. If I manually add that dep to deps.edn and call (sync-deps), I get the same error.

The full error is:


  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (28 frames hidden)

1. Unhandled clojure.lang.ExceptionInfo
   Could not find artifact org.apache:apache:pom:8
   {:via
    [{:type org.eclipse.aether.resolution.ArtifactDescriptorException,
      :message
      "Failed to read artifact descriptor for com.datomic:datomic-lucene-core:jar:3.3.0",
      :at
      [org.apache.maven.repository.internal.DefaultArtifactDescriptorReader
       loadPom
       "DefaultArtifactDescriptorReader.java"
       305]}
     {:type org.apache.maven.model.resolution.UnresolvableModelException,
      :message "Could not find artifact org.apache:apache:pom:8",
      :at
      [org.apache.maven.repository.internal.DefaultModelResolver
       resolveModel
       "DefaultModelResolver.java"
       176]}
     {:type org.eclipse.aether.resolution.ArtifactResolutionException,
      :message "Could not find artifact org.apache:apache:pom:8",
      :at
      [org.eclipse.aether.internal.impl.DefaultArtifactResolver
       resolve
       "DefaultArtifactResolver.java"
       431]}
     {:type org.eclipse.aether.transfer.ArtifactNotFoundException,
      :message "Could not find artifact org.apache:apache:pom:8",
      :at
      [org.eclipse.aether.internal.impl.DefaultArtifactResolver
       resolve
       "DefaultArtifactResolver.java"
       421]}],
    :trace
    [[org.eclipse.aether.internal.impl.DefaultArtifactResolver
      resolve
      "DefaultArtifactResolver.java"
      421]
     [org.eclipse.aether.internal.impl.DefaultArtifactResolver
      resolveArtifacts
      "DefaultArtifactResolver.java"
      235]
     [org.eclipse.aether.internal.impl.DefaultArtifactResolver
      resolveArtifact
      "DefaultArtifactResolver.java"
      212]
     [org.apache.maven.repository.internal.DefaultModelResolver
      resolveModel
      "DefaultModelResolver.java"
      172]
     [org.apache.maven.repository.internal.DefaultModelResolver
      resolveModel
      "DefaultModelResolver.java"
      222]
     [org.apache.maven.model.building.DefaultModelBuilder
      readParentExternally
      "DefaultModelBuilder.java"
      1150]
     [org.apache.maven.model.building.DefaultModelBuilder
      readParent
      "DefaultModelBuilder.java"
      916]
     [org.apache.maven.model.building.DefaultModelBuilder
      build
      "DefaultModelBuilder.java"
      361]
     [org.apache.maven.model.building.DefaultModelBuilder
      build
      "DefaultModelBuilder.java"
      267]
     [org.apache.maven.repository.internal.DefaultArtifactDescriptorReader
      loadPom
      "DefaultArtifactDescriptorReader.java"
      296]
     [org.apache.maven.repository.internal.DefaultArtifactDescriptorReader
      readArtifactDescriptor
      "DefaultArtifactDescriptorReader.java"
      171]
     [org.eclipse.aether.internal.impl.DefaultRepositorySystem
      readArtifactDescriptor
      "DefaultRepositorySystem.java"
      263]
     [clojure.tools.deps.extensions.maven$read_descriptor
      invokeStatic
      "maven.clj"
      115]
     [clojure.tools.deps.extensions.maven$read_descriptor invoke "maven.clj" 106]
     [clojure.tools.deps.extensions.maven$eval1218$fn__1219
      invoke
      "maven.clj"
      146]
     [clojure.lang.MultiFn invoke "MultiFn.java" 244]
     [clojure.tools.deps$expand_deps$children_task__778$fn__780$fn__781
      invoke
      "deps.clj"
      407]
     [clojure.lang.AFn applyToHelper "AFn.java" 152]
     [clojure.lang.AFn applyTo "AFn.java" 144]
     [clojure.core$apply invokeStatic "core.clj" 667]
     [clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1990]
     [clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1990]
     [clojure.lang.RestFn invoke "RestFn.java" 425]
     [clojure.lang.AFn applyToHelper "AFn.java" 156]
     [clojure.lang.RestFn applyTo "RestFn.java" 132]
     [clojure.core$apply invokeStatic "core.clj" 671]
     [clojure.core$bound_fn_STAR_$fn__5818 doInvoke "core.clj" 2020]
     [clojure.lang.RestFn invoke "RestFn.java" 397]
     [clojure.lang.AFn call "AFn.java" 18]
     [java.util.concurrent.FutureTask run "FutureTask.java" 317]
     [java.util.concurrent.ThreadPoolExecutor
      runWorker
      "ThreadPoolExecutor.java"
      1144]
     [java.util.concurrent.ThreadPoolExecutor$Worker
      run
      "ThreadPoolExecutor.java"
      642]
     [java.lang.Thread run "Thread.java" 1570]],
    :cause "Could not find artifact org.apache:apache:pom:8"}
               interop.clj:   81  clojure.tools.deps.interop/invoke-tool
               interop.clj:   41  clojure.tools.deps.interop/invoke-tool
                  deps.clj:   48  clojure.repl.deps/add-libs
                  deps.clj:   57  clojure.repl.deps/add-lib
                  deps.clj:   57  clojure.repl.deps/add-lib
                      REPL:   28  user/eval11698
                      REPL:   28  user/eval11698
             Compiler.java: 7700  clojure.lang.Compiler/eval
             Compiler.java: 7655  clojure.lang.Compiler/eval
                  core.clj: 3232  clojure.core/eval
                  core.clj: 3228  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  428  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  459  clojure.main/repl/fn
                  main.clj:  459  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1526  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java: 1570  java.lang.Thread/run

Environment & Version information

CIDER version information

;; CIDER 1.15.0-snapshot (package: 1.15.0-snapshot), nREPL 1.1.2
;; Clojure 1.12.0-rc1, Java 22.0.2

Lein / Clojure CLI version

Clojure CLI version 1.11.4.1474

Emacs version

29.4

Operating system

macOS Sonoma 14.6.1

JDK distribution

openjdk version "22.0.2" 2024-07-16

bbatsov commented 3 months ago

@alexander-yakushev Can you take a look at this?

filipesilva commented 3 months ago

(added the contents of my ~/.clojure/deps.edn with regards to the initial CIDER sync-deps btw)

alexander-yakushev commented 3 months ago

The repro worked for me in CIDER.

Please, try jacking in with -Srepro. To do that, execute C-u M-x cider-jack-in and then add -Srepro after the clojure binary in the command.

filipesilva commented 3 months ago

Like this?

CleanShot 2024-08-26 at 10 19 14@2x

I still get the same error. I don't understand why the CIDER process would need -Srepro while the plain clj one doesn't though.

alexander-yakushev commented 3 months ago

I see you have nREPL 1.1.2 and cider-nrepl 0.48.0 being injected. Given that you are on the latest MELPA CIDER, it looks like you have those two versions customized through cider-injected-nrepl-version and cider-injected-middleware-version. Can you please reset those customizations so that the default latest versions are injected? (that would be 1.3.0 and 0.49.3).

filipesilva commented 3 months ago

I don't have those customizations. Maybe it was because I was on CIDER 1.15.0-snapshot? I've tried updating my doom emacs packages now, and I'm at CIDER 1.15.0.

;; CIDER 1.15.0 (Cogne), nREPL 1.2.0
;; Clojure 1.12.0-rc1, Java 22.0.2
...
;;  Startup: bash /Users/filipesilva/.emacs.d/.local/straight/build-29.4/cider/clojure.sh /opt/homebrew/bin/clojure -Srepro -Sdeps \{\:deps\ \{nrepl/nrepl\ \{\:mvn/version\ \"1.2.0\"\}\ cider/cider-nrepl\ \{\:mvn/version\ \"0.49.0\"\}\ refactor-nrepl/refactor-nrepl\ \{\:mvn/version\ \"3.10.0\"\}\}\ \:aliases\ \{\:cider/nrepl\ \{\:main-opts\ \[\"-m\"\ \"nrepl.cmdline\"\ \"--middleware\"\ \"\[refactor-nrepl.middleware/wrap-refactor\,cider.nrepl/cider-middleware\]\"\]\}\}\} -M:cider/nrepl

These seem right according to https://github.com/clojure-emacs/cider/releases/tag/v1.15.0. Still same error though.

vemv commented 3 months ago

You're using enrich-classpath.

I think I heard of this incompatibility somewhere in Clojurians Slack. There isn't any inherent reason for it, would have to allocate some time to investigation.

Feel free to disable it: (setq cider-enrich-classpath nil)

filipesilva commented 3 months ago

Yeap that was it @vemv! Error is gone now, and the initial sync-deps did not list everything in ./clojure/deps.edn either. Thank you!