如何使用公司代理或 maven 镜像后面的模板启动一个新的 Clojure lein 项目

How to start a new Clojure lein project using a template behind corporate proxy or maven mirror

我正在尝试在公司代理或本地 Maven 镜像后面使用 lein 新模板构建,但失败了:

C:\development\clojure> lein new luminus guestbook +h2
Failed to resolve version for luminus:lein-template:jar:RELEASE: Could not find metadata luminus:lein-template/maven-metadata.xml in local (C:\Users\username\.m2\repository)
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.
Could not find template luminus on the classpath.

在 profiles.clj 中放置以下行似乎没有效果:

:mirrors {"central" {:name "central" 
  :url "http://server.company_name.com:8080/artifactory/maven.central/"}} 

环境变量(大小写似乎也没有影响):

HTTP_PROXY=http://username:password@proxy.company_name.com:8080
HTTPS_PROXY=https://username:password@proxy.company_name.com:8080
HTTP_NO_PROXY=*.company_name.com
HTTP_CLIENT=wget --no-check-certificate -O

注意:我还指定了 HTTP/S 没有用户名和密码的代理,这导致了同样的失败。

我也无法确定如何生成调试级别的日志记录来帮助排除故障。

Leiningen 2.7.0 on Java 1.8.0_144 Java HotSpot(TM) 64 位服务器虚拟机

Clojure 1.8.0

我在 clojars.org 找到了 luminus:lein-template:2.9.11.90 工件,并使用 Maven 将其手动检索到我的本地 M2 存储库中。

C:\development\clojure> mvn dependency:get -DremoteRepositories=https://clojars.org/repo -Dartifact=luminus:lein-template:2.9.11.90
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) @ standalone-pom ---
[INFO] Resolving luminus:lein-template:jar:2.9.11.90 with transitive dependencies
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.160 s
[INFO] Finished at: 2017-09-30T16:58:11-04:00
[INFO] Final Memory: 11M/216M
[INFO] ------------------------------------------------------------------------

一旦这个工件在本地可用,我就能够成功地使用模板创建项目:

C:\development\clojure> lein new luminus guestbook +h2
Generating a Luminus project.

完成并移动到新项目目录后,我可以使用 "lein run".

成功下载依赖项和 运行 项目

这并没有解决 lein 在从模板创建项目时使用代理配置的问题,但确实提供了解决方法。

我更新了文件 ~.m2/settings.xml 其中包含 Maven 配置设置如下:

<settings ...>
  ...
  <profiles>
    ...
    <profile>
      <id>alwaysActive</id>
      <repositories>
        ...
        <repository>
          <id>clojars</id>
          <name>Repository for Clojure builds</name>
                    <snapshots> 
                        <enabled>false</enabled> 
                    </snapshots> 
          <url>https://clojars.org/repo</url>
          <layout>default</layout>
        </repository>
      </repositories>
    </profile>

  </profiles>

  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
  </activeProfiles>

</settings>

这个版本的 Lein 似乎添加了 Clojars 存储库搜索路径来解决依赖关系,但没有为项目模板添加。通过进行此 Maven 配置更改,它会导致 Lein 调用的 Maven 自动搜索其他 Clojars 存储库。这似乎是不一致的行为,希望在 Lein 的未来版本中得到解决。