无法从 central/clojars 中提取依赖项

Unable to pull dependencies from central/clojars

我的 project.clj 文件看起来像 -

(defproject somename "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [org.apache.kafka/kafka-clients "0.11.0.2"]]
  :main somename.core
  :target-path "target/%s"
  :profiles {:dev {:dependencies [[lein-light-nrepl "0.3.3"]
                                  [enlive "1.1.6"]
                                  [cheshire "5.8.0"]
                                  [criterium "0.4.4"]]}}
  :repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]})

lein repl 在项目目录之外工作正常。

$ lein repl
nREPL server started on port 34420 on host 127.0.0.1 - 
nrepl://127.0.0.1:34420
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_161-b12
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
    Source: (source function-name-here)
    Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
    Results: Stored in vars *1, *2, *3, an exception in *e

user=> 

但是,对于这个项目,我在做的时候lein deps,是无法拉取依赖的。 我收到类似 -

的错误
Could not transfer artifact org.apache.kafka:kafka-
clients:pom:0.11.0.2 from/to central (https://repo1.maven.org/maven2/): Connect to  [localhost/127.0.0.1] failed: Connection refused (Connection refused)
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

莱因和java版本如下-

$ lein version
Leiningen 2.7.1 on Java 1.8.0_161 Java HotSpot(TM) 64-Bit Server VM

$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

请帮我解决这个问题。

我之前遇到过完全相同的问题。我想这是因为一些硬编码的 repo url 使用 HTTP 方案而不是 HTTPS。 将其放入您的 project.clj 应该会有所帮助:

:repositories [["jitpack" "https://jitpack.io"]
               ["central" "https://repo1.maven.org/maven2"]
               ["clojure" "https://build.clojure.org/releases"]
               ["clojars" "https://clojars.org/repo"]
               ["java.net" "https://download.java.net/maven/2"]
               ["jboss.release" "https://repository.jboss.org/nexus/content/groups/public"]
               ["terracotta-releases" "https://www.terracotta.org/download/reflector/releases"]
               ["terracotta-snapshots" "https://www.terracotta.org/download/reflector/snapshots"]
               ["apache.snapshots" "https://repository.apache.org/snapshots"]]