lein 新建 reagent-frontend 工程失败问题


最近打算用 ClojureScript 做点 web 应用,就准备实践下 Reagent ,它是一个 React.js 的极简封装(A minimalistic ClojureScript interface to React.js),通过官网的几个例子可以看到,确实很简洁。

看花容易绣花难,那就先搞一个本地工程玩一下看。Leiningen 命令有两种:

  1. lein new reagent myproject 创建包含前后端的工程
  2. lein new reagent-frontend myproject 创建仅前端工程

简单起见,创建一个仅包含前端的工程足够了,因此使用第二种方法。但是诡异的是,命令居然报错了:

$ lein new reagent-frontend play-reagent-frontent
Failed to resolve version for reagent-frontend:lein-template:jar:RELEASE: Could not find metadata reagent-frontend:lein-template/maven-metadata.xml in local (/home/whatacold/.m2/repository)
Failed to read artifact descriptor for reagent-frontend:lein-template:jar:RELEASE
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Could not find template reagent-frontend on the classpath.

而且这个报错在网上也没搜到直接有用的信息, lein 模板工程里倒是有一个相关的 issue ,但它是针对 reagent 模板的(对应上边第一条 lein 命令),而且内容已好几年了。同时我也在 slack 频道上问过,同样也没有得到有用的信息。

无奈之下,只好在 issue 上留言跟进,好在 yogthos 看到了之后给了一些指引,这才发现 ~/.m2/repository/reagent-frontend/lein-template/resolver-status.properties 文件全是报错:

$ cat ~/.m2/repository/reagent-frontend/lein-template/resolver-status.properties
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Tue Aug 31 00:36:44 CST 2021
maven-metadata-tsinghua.xml/@192.168.1.1\:12345>@default-tsinghua-https\://mirrors.tuna.tsinghua.edu.cn/clojars/.lastUpdated=1630341404261
maven-metadata-aliyun.xml.error=Could not transfer metadata reagent-frontend\:lein-template/maven-metadata.xml from/to aliyun (https\://maven.aliyun.com/repository/public/)\: Checksum validation failed, no checksums available
maven-metadata-aliyun.xml/@192.168.1.1\:12345>@default-aliyun-https\://maven.aliyun.com/repository/public/.lastUpdated=1630341404488
maven-metadata-tsinghua.xml.error=Could not transfer metadata reagent-frontend\:lein-template/maven-metadata.xml from/to tsinghua (https\://mirrors.tuna.tsinghua.edu.cn/clojars/)\: Checksum validation failed, expected f5a8f4da358ee257ead04c314c047dedefbe2962 but is 87caff4a2f9beaad6c80c4f015ac1db0435d27b3

根据这个错误,推断是因为 aliyun/tsinghua 的镜像有问题,导致 lein 安装不到依赖。

那不如去掉镜像试试?

于是,就把 ~/.lein/profiles.clj 中的镜像配置去掉,并且 rm -rf ~/.m2/repository/reagent-frontend 删掉已有的 maven 目录。

再次执行命令,就真的 ok 了:

lein new reagent-frontend myproject
Generating fresh 'lein new' Reagent frontend project.

此时正确的 ~/.m2/repository/reagent-frontend/lein-template/resolver-status.properties 是这样的:

#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Sun Sep 05 10:28:09 CST 2021
maven-metadata-clojars.xml.lastUpdated=1630808889985
maven-metadata-central.xml.lastUpdated=1630808888850
maven-metadata-central.xml.error=

也可以看看

comments powered by Disqus