Clojure China

关于lein的几个入门级问题?(已完结)

lein
clojure
#1

小弟上一次提问是2016年,两年时间,因为事情比较多,没有捣鼓clojure,惭愧啊。最近又有些手痒,遂开始捯饬lein。我的开发环境是sublime text3 + lein2.8.1 + clojure-1.9.0.jar。因为我对maven的认识也不是很深刻。所以产生了几个关于lein问题:
1.以win7为例(当然也可以以linux或mac为例),lein的本地仓库在哪个目录?
2.如果有maven的本地仓库,是否可以共用?还是本身就是共用的?
3.如何在命令行用lein更新项目依赖?比如mavene可以update project(-U),在eclipse中修改pom.xml都会自动触发依赖关系更新。在lein的help中看到了个:“update-in Perform arbitrary transformations on your project map.”关键是怎么用,我做了如下尝试(不知为毛图片老是上传失败,直接上文本。‘my-project’是我的项目根目录),然并卵。
D:\clojure-workspace\my-project
λ lein update-in
Wrong number of arguments to update-in task.
Expected [key-path f & args]

D:\clojure-workspace\my-project
λ lein update-in project.clj
Wrong number of arguments to update-in task.
Expected [key-path f & args]

ps:其实前2个问题其实可以归结为一个:我在lein.bat(windows)脚本里面不知道指定本地仓库位置的配置项。比如看到个%LEIN_JAR%也不知道是搞毛的。而这些个配置项在maven的settings.xml中的都是有的。

#2

无知的我真可怕,自己顶自己。经过学习,lein 依赖更新cmd的命令是先cd到项目根目录再输入: lein search project.clj。PS:这里有个错误,网上说正确的命令是 lein deps 。但之前我还是有疑惑,因为同一台电脑上安装多个版本的lein对一个项目的依赖管理居然不是同步刷新的!比如说同一个项目my-project 。我修改project.clj后用独立版lein执行:lein deps,打开counterclockwise(ccw)发现project.clj已经改变,但ccw集成的lein的leiningen dependencies却没有同步变化,必须手动执行一次update dependencies才能让ccw内嵌版的lein获取最新的依赖关系。这让我一度怀疑lein deps 命令的真实性。
通过下载counterclockwise独立版,发现如果不自定义本地仓库位置,lein和maven共用C:\Users\xxx\.m2 仓库。我顺便试了下lighttable这个ide,鉴于本人水平有限,使用lighttable连接时总是报连接失败。有一次报找不到这个default.clj。个人猜想这个ide没有先从本地仓库找依赖,也没去maven中央库找,而是直接去clojars去Retrieving deps。没代理,连不上,当然会失败。错误信息贴出来:
We couldn’t connect.

Looks like there was an issue trying to connect to the project. Here’s what we got:
final project: {:description FIXME: write description, :compile-path D:\clojure-workspace\my-project\target\classes, :deploy-repositories [[clojars {:url https://clojars.org/repo/, :password :gpg, :username :gpg}]], :group my-project, :license {:name Eclipse Public License, :url http://www.eclipse.org/legal/epl-v10.html}, :resource-paths (D:\clojure-workspace\my-project\dev-resources D:\clojure-workspace\my-project\resources), :uberjar-merge-with {META-INF/plexus/components.xml leiningen.uberjar/components-merger, data_readers.clj leiningen.uberjar/clj-map-merger, #“META-INF/services/." [clojure.core/slurp (fn [p1__949__951__auto__ p2__950__952__auto__] (clojure.core/str p1__949__951__auto__
p2__950__952__auto__)) clojure.core/spit]}, :name my-project, :checkout-deps-shares [:source-paths :test-paths :resource-paths :compile-path #'leiningen.core.classpath/checkout-deps-paths], :source-paths (D:\clojure-workspace\my-project\src), :eval-in :subprocess, :repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :test-paths (D:\clojure-workspace\my-project\test), :target-path D:\clojure-workspace\my-project\target, :prep-tasks [javac compile], :native-path D:\clojure-workspace\my-project\target\native, :offline? false, :root D:\clojure-workspace\my-project, :pedantic? ranges, :clean-targets [:target-path], :plugins [], :url http://example.com/FIXME, :plugin-repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :version 0.1.0-SNAPSHOT, :jar-exclusions [#”^."], :global-vars {}, :uberjar-exclusions [#"(?i)^META-INF/[^/].(SF|RSA|DSA)$"], :jvm-opts [], :dependencies ([org.clojure/clojure 1.9.0] [org.clojure/core.specs.alpha 0.1.24 :exclusions ([org.clojure/clojure] [org.clojure/spec.alpha])] [org.clojure/spec.alpha 0.1.143 :exclusions ([org.clojure/clojure])] [clj-http/clj-http 3.8.0] [org.clojure/tools.nrepl 0.2.10 :exclusions ([org.clojure/clojure])] [clojure-complete/clojure-complete 0.2.3 :exclusions ([org.clojure/clojure])] [lein-light-nrepl/lein-light-nrepl 0.3.0] [lein-light-nrepl-instarepl/lein-light-nrepl-instarepl 0.3.1]), :release-tasks [[vcs assert-committed] [change version leiningen.release/bump-version release] [vcs commit] [vcs tag] [deploy] [change version leiningen.release/bump-version] [vcs commit] [vcs push]], :repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops], :init (clojure.core/swap! lighttable.nrepl.core/my-settings clojure.core/merge {:name my-project 0.1.0-SNAPSHOT, :project (quote {:description FIXME: write description, :compile-path D:\clojure-workspace\my-project\target\classes, :deploy-repositories [[clojars {:url https://clojars.org/repo/, :password :gpg, :username :gpg}]], :group my-project, :license {:name Eclipse Public License, :url http://www.eclipse.org/legal/epl-v10.html}, :resource-paths (D:\clojure-workspace\my-project\dev-resources D:\clojure-workspace\my-project\resources), :uberjar-merge-with {META-INF/plexus/components.xml leiningen.uberjar/components-merger, data_readers.clj leiningen.uberjar/clj-map-merger, #"META-INF/services/." [clojure.core/slurp (fn* [p1__949__951__auto__ p2__950__952__auto__] (clojure.core/str p1__949__951__auto__
p2__950__952__auto__)) clojure.core/spit]}, :name my-project, :checkout-deps-shares [:source-paths :test-paths :resource-paths :compile-path #'leiningen.core.classpath/checkout-deps-paths], :source-paths (D:\clojure-workspace\my-project\src), :eval-in :subprocess, :repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :test-paths (D:\clojure-workspace\my-project\test), :target-path D:\clojure-workspace\my-project\target, :prep-tasks [javac compile], :native-path D:\clojure-workspace\my-project\target\native, :offline? false, :root D:\clojure-workspace\my-project, :pedantic? ranges, :clean-targets [:target-path], :plugins [], :url http://example.com/FIXME, :plugin-repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :version 0.1.0-SNAPSHOT, :jar-exclusions [#"^."], :global-vars {}, :uberjar-exclusions [#"(?i)^META-INF/[^/]*.(SF|RSA|DSA)$"], :jvm-opts [], :dependencies ([org.clojure/clojure 1.9.0] [org.clojure/core.specs.alpha 0.1.24 :exclusions ([org.clojure/clojure] [org.clojure/spec.alpha])] [org.clojure/spec.alpha 0.1.143 :exclusions ([org.clojure/clojure])] [clj-http/clj-http 3.8.0] [org.clojure/tools.nrepl 0.2.10 :exclusions ([org.clojure/clojure])] [clojure-complete/clojure-complete 0.2.3 :exclusions ([org.clojure/clojure])]), :release-tasks [[vcs assert-committed] [change version leiningen.release/bump-version release] [vcs commit] [vcs tag] [deploy] [change version leiningen.release/bump-version] [vcs commit] [vcs push]], :test-selectors {:default (constantly true)}})})}, :test-selectors {:default (constantly true)}}
Error loading lighttable.nrepl.handler: clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec:
In: [1] val: ((require [clojure.string :as string] [cljs.source-map.base64 :as base64])) fails spec: :clojure.core.specs.alpha/ns-form at: [:args] predicate: (cat :docstring (? string?) :attr-map (? map?) :clauses :clojure.core.specs.alpha/ns-clauses), Extra input
#:clojure.spec.alpha{:problems [{:path [:args], :reason “Extra input”, :pred (clojure.spec.alpha/cat :docstring (clojure.spec.alpha/? clojure.core/string?) :attr-map (clojure.spec.alpha/? clojure.core/map?) :clauses :clojure.core.specs.alpha/ns-clauses), :val ((require [clojure.string :as string] [cljs.source-map.base64 :as base64])), :via [:clojure.core.specs.alpha/ns-form], :in [1]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x62cf6a84 “[email protected]”], :value (cljs.source-map.base64-vlq (require [clojure.string :as string] [cljs.source-map.base64 :as base64])), :args (cljs.source-map.base64-vlq (require [clojure.string :as string] [cljs.source-map.base64 :as base64]))}, compiling:(cljs/source_map/base64_vlq.clj:1:1)
Exception in thread “main” java.lang.RuntimeException: Unable to resolve var: lighttable.nrepl.handler/lighttable-ops in this context, compiling:(C:\Users\jack\AppData\Local\Temp\form-init6742352915621721344.clj:1:3761)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7010)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3881)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3881)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.access$300(Compiler.java:38)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6368)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5460)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4022)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.eval(Compiler.java:7059)
at clojure.lang.Compiler.eval(Compiler.java:7052)
at clojure.lang.Compiler.load(Compiler.java:7514)
at clojure.lang.Compiler.loadFile(Compiler.java:7452)
at clojure.main$load_script.invokeStatic(main.clj:278)
at clojure.main$init_opt.invokeStatic(main.clj:280)
at clojure.main$init_opt.invoke(main.clj:280)
at clojure.main$initialize.invokeStatic(main.clj:311)
at clojure.main$null_opt.invokeStatic(main.clj:345)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.invokeStatic(main.clj:424)
at clojure.main$main.doInvoke(main.clj:387)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:702)
at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: lighttable.nrepl.handler/lighttable-ops in this context
at clojure.lang.Util.runtimeException(Util.java:221)
at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:720)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
… 34 more
clojure.lang.ExceptionInfo: Subprocess failed {:exit-code 1}
at clojure.core$ex_info.invoke(core.clj:4593)
at leiningen.core.eval$fn__2428.invoke(eval.clj:236)
at clojure.lang.MultiFn.invoke(MultiFn.java:233)
at leiningen.core.eval$eval_in_project.invoke(eval.clj:337)
at clojure.lang.AFn.applyToHelper(AFn.java:160)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invoke(core.clj:632)
at leiningen.repl$repl.doInvoke(repl.clj:322)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at leiningen.light_nrepl$light.invoke(light_nrepl.clj:77)
at leiningen.light_nrepl$_main.doInvoke(light_nrepl.clj:85)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at leiningen.light_nrepl.main(Unknown Source)


新鲜出炉的错误信息,我一直在connecting。每次都有一定几率报出不同的失败原因,真心觉得奇葩,果断放弃这个ide.那些说lighttable大法好的大神我就不说什么了,如果你也是小白,老老实实用eclipse或idea的插件吧。追求装b极客风的同学用EMACS/vim + 插件吧。

#3

追求装b极客风的同学用EMACS/vim + 插件吧。

虽然这话是没错,但还有一种可能,就是信仰,可以看看 https://emacs-china.org/

当然,新手还是用最大众的 IDE 好些,lighttable 还是需要有些 debug 功力才能用好的。

#4

信仰的观点,我完全赞同。我还是个小白,还需多学习:slightly_smiling:

#6

入门的朋友可以看看这个:Clojure学习资源
适合和我一样自学的小白,里面有很多资源,大家一起学起来