leiningen - 如何添加本地 jar 的依赖项?
我想使用 leiningen 来构建和开发我的 clojure 项目。有没有办法修改project.clj以告诉它从本地目录中选择一些jar?
我有一些专有的 jar 无法上传到公共存储库。
另外,leiningen 可以用来维护 clojure 项目的“lib”目录吗?如果我的一堆 clojure 项目共享相同的 jar,我不想为每个项目维护一个单独的副本。
谢谢
I want to use leiningen to build and develop my clojure project. Is there a way to modify project.clj to tell it to pick some jars from local directories?
I have some proprietary jars that cannot be uploaded to public repos.
Also, can leiningen be used to maintain a "lib" directory for clojure projects? If a bunch of my clojure projects share the same jars, I don't want to maintain a separate copy for each of them.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
只需在 project.clj 文件中使用 :resource-paths 即可。例如,我使用它来连接到 Siebel 服务器。刚刚在我的项目目录中创建了一个 resources 目录,并将 jar 文件复制到其中。但是当然您可以使用更通用的目录:
然后从 lein repl 我可以创建 Siebel Data Bean 实例,例如,
如果您有较新的 Java 版本,您当然可以在路径规范中使用通配符,例如这是一个更通用的目录:
Just use :resource-paths in your project.clj file. I use it, e.g. to connect to Siebel servers. Just created a resources directory in my project directory and copied the jar files in there. But of course you could use a more generic directory:
Then from the lein repl I can create Siebel Data Bean instances, e.g.
If you have a newer Java version you can of course use wildcards in your path specification like this for a more general directory:
在项目中创建一个目录:
mkdir maven_repository
将本地 jar 添加到此存储库:
例如,此命令将
jaad-0.8.3.jar
文件添加到maven存储库:
mvn 部署:部署文件 -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository
project.clj
:repositories {"local" "file:maven_repository"}
现在常规的
lein deps
应该可以工作:$ lein deps
从本地下载:jaad/jaad/0.8.3/jaad-0.8.3.pom
从本地传输 0K
[警告] *** 校验和失败 - 检索 jaad/jaad/0.8.3/jaad-0.8.3.pom 的校验和文件时出错 - 忽略
该警告可以忽略,因为 jar 将被检入项目中并且不是从互联网上下载的。
原始来源:在 Leiningen 中使用本地 JAR< /a>(复制后已更改)
Create a directory in the project:
mkdir maven_repository
Add local jars to this repository:
For example, this command adds the
jaad-0.8.3.jar
file to the mavenrepository:
mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository
Add the following to
project.clj
:repositories {"local" "file:maven_repository"}
Now a regular
lein deps
should work:$ lein deps
Downloading: jaad/jaad/0.8.3/jaad-0.8.3.pom from local
Transferring 0K from local
[WARNING] *** CHECKSUM FAILED - Error retrieving checksum file for jaad/jaad/0.8.3/jaad-0.8.3.pom - IGNORING
The warning can be ignored, since the jar will be checked into the project and not downloaded from the internet.
Original source: Using local JAR's with Leiningen (changed since copying)
您可以将您的私有 jar 放在
lib/
中,并且出于 lein swank 等目的,它们将位于类路径中;这似乎确实违背了使用依赖项管理工具的意义,但如果您实际上不想管理这些依赖项,您可以将 Leiningen 视为“开源依赖项管理工具”,并且可能要小心与lein clean
。随着情况变得更加复杂——涉及到更多数量的私有 jar,它们不断发展,您需要考虑它们的一些版本控制信息——Arthur 创建私有 Maven 存储库的想法可能更合适。
(HR 表示 Leiningen 特定部分的截止点...继续下面的内容,了解有关 Clojure 领域中的一般构建/依赖管理工具故事的信息,包括一些我认为在您的情况下可能非常有用的链接。 )
此外,到目前为止,对于 Clojure 最好的构建工具这个问题还没有达成普遍共识,而 Leiningen 在赢得关注度的同时,也在功能和完善方面不断获得进步——这意味着,特别是它尚未完成。这里引用 Pragmatic Bookshelf 的《Programming Clojure》一书的作者 Stuart Halloway 的话:“我的 2c:Leiningen 是重要的一步,但还有很多工作要做。”有关 Clojure 空间中关于构建工具等的完整帖子和非常有趣的讨论,请参阅 Leiningen、Clojure 和库:我缺少什么? Clojure Google 小组上的帖子。许多参与者特别提到需要不包含在任何存储库(本地或其他)中的本地依赖项,并详细说明了他们针对此类场景提出的解决方案。也许您可以看看那里是否有任何东西可以解决您现在的问题/将来当功能集成熟时可以解决它?
无论如何,莱宁根实际上可能还没有为某些复杂的场景准备好故事。如果您觉得这可能适合您的情况(我的意思是在您考虑私有回购想法之后),这里有一些来自上述线程的基于 Maven 的替代方案的链接: 多语言 Maven, clojure-maven-plugin< /a>; 此博客文章旨在对尝试使用的人有用Maven 与 Clojure。我记得,Meikel Brandmeyer(也在他的在线账号 kotarak 下的 SO 上)使用 Gradle(一个 Groovy 构建系统)和一个名为 Clojuresque 的插件来适应 Clojure;我自己从未尝试过,因为我对 Groovy 一无所知,但他声称用它进行了一个非常好的构建行为,我相信这与 Maven 无关——这本身就是一个优点对于我们中的一些人来说。 :-)
You could put your private jars in
lib/
and they'd be on the classpath for the purposes oflein swank
and the like; this does seem to defeat the point of using a dependency management tool, though if you don't actually want those dependencies managed, you could treat Leiningen as an "open source dependencies management tool" and maybe be careful withlein clean
.As the situation becomes more complex -- there's a larger number of private jars involved, they evolve and you need to take some versioning info on them into account -- Arthur's idea of creating a private Maven repo may be more appropriate.
(The HR signifies Leiningen-specific part cut-off point... Continue below for information on the general build / dependency management tooling story in Clojure land, including some links which I think could come in very handy in your situation.)
Also, as of yet, there is no universal agreement on the question of which is the best build tool for Clojure, and Leiningen, while gaining in mindshare, is also constantly gaining in the areas features and polish -- meaning, in particular, that it's not yet complete. Here's a quote from Stuart Halloway, the author of Pragmatic Bookshelf's "Programming Clojure": "My 2c: Leiningen is an important step, but there is still plenty to do." For the full posting and a very interesting discussion re: build tools and the like in Clojure space, see the Leiningen, Clojure and libraries: what am I missing? thread on the Clojure Google group. Many participants specifically mention the need to have local dependencies not contained in any repositories, local or otherwise, and elaborate on the solutions they've come up with for such scenarios. Perhaps you could see if there's anything over there which can solve your problem now / might solve it in the future, when feature sets mature?
Anyway, it is possible that Leiningen may not in fact have a good story ready yet for some complex scenarios. If you feel this may be true of your case (and I mean after you consider the private repo idea), here's some links to maven-based alternatives taken from the above mentioned thread: polyglot maven, clojure-maven-plugin; this blog posting aims to be useful to people trying to use maven with Clojure. As I recall, Meikel Brandmeyer (also on SO under his online handle of kotarak) uses Gradle (a Groovy build system) with a plugin to accomodate Clojure called Clojuresque; I never tried it myself, as don't know the first thing about Groovy, but he claims to run a very nice building act with it and I believe it's got nothing to do with maven -- something which is a plus in and of itself for some of us. :-)
我找到 lein pom;莱因罐子; lein install 在开发库时效果很好。
在正在开发的库中执行此操作,需要它的应用程序将使用它,而不需要任何
:repositories
foo 。另外,
lein do pom, jar, install
稍微简洁一些。这允许像任何其他
一样调用库:dependency [[project-name "version"]]
I find
lein pom; lein jar; lein install
works well when developing libraries.Do this in the library being developed and your application requiring it will use it without any
:repositories
foo required.Alternatively,
lein do pom, jar, install
is slightly more concise.This allows calling the library like any other
:dependencies [[project-name "version"]]
我相信“正确”的方法是 创建一个私有 Maven 存储库 这样您就可以将罐子存储在一个位置,并且您的所有分支机构等都会收到更改。这对于你所做的事情来说可能有点过分了。我很好奇这些是否是更简单的方法。
I believe the "correct" approach is to create a private Maven Repository so that you can store the jars in a single location and all your branches etc will pick up the changes. This may be overkill for what your doing. I'm curious if these is an easier way.
您可能喜欢使用插件 lein-localrepo:https://github.com/kumarshantanu/lein-本地仓库
You may like to use the plugin
lein-localrepo
: https://github.com/kumarshantanu/lein-localrepo最近的一项开发是 Phil 针对 Leiningen 的
s3-wagon-private
插件:https: //github.com/technomancy/s3-wagon-private这应该允许您将工件发布到私有远程存储库。
A recent development is Phil's
s3-wagon-private
plugin for Leiningen: https://github.com/technomancy/s3-wagon-privateThis should allow you to publish artifacts to a private remote repo.
这些解决方案都没有对我有用。相反,我安装了本地存储库,并使用 maven 在本地存储库中安装 jar 文件,并将本地存储库添加到我的 project.clj
在命令行中:
我像这样编写我的 project.clj:
希望它有帮助。
[参考:https://gist.github.com/stuartsierra/3062743]
None of these solutions worked me. Instead I have installed a local repository, and used maven to install the jar file in the local repo, and added the local repo to my project.clj
In command line:
And I write my project.clj like this:
Hope it helps.
[REFERENCE: https://gist.github.com/stuartsierra/3062743 ]
也许看看这个 以前的答案,我提供了设置项目本地存储库(通过
file://
访问)的分步说明,您可以在其中安装 jar。Maybe have a look at this previous answer, I provide step by step instructions to setup a repository local to the project (accessed through
file://
) in which you could install your jars.尝试我的解决方案如何构建具有依赖项的 jar 文件
http://middlesphere-1 .blogspot.ru/2014/06/how-to-make-jar-with-dependency-using.html
Try my solution how to build jar file with dependencies
http://middlesphere-1.blogspot.ru/2014/06/how-to-make-jar-with-dependencies-using.html
最好的选择是设置一个私有 JFrog/Nexus 工件并在那里部署快照/版本,然后将该工件添加为项目中的存储库。clj
其他更简单的方法是
静态 HTTP 最简单的私有存储库是Web 服务器指向一个充满静态文件的目录。如果该目录是运行 Leiningen 的计算机的本地目录,则可以在 :repositories 中使用 file:/// URL 来进行部署。
SCP
如果您已经使用 SSH 公钥设置了服务器,则 scp 传输是发布和使用私有依赖项的简单方法。将以下内容放在 defproject 中:
然后将以下内容放在 defproject 之外:
如果您设置 nginx 或类似的东西来通过 HTTP 提供存储库目录,则还可以使用 scp 传输部署到存储库并通过 http 使用它。
注意:不再支持 SCP 部署到 Clojars
原始来源在这里 https:/ /github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md
Best option is to setup a private JFrog/Nexus artifactory and deploy your snapshots/releases there and then add that artifiactory as repositories in you project.clj
Other simpler ways are
Static HTTP The simplest kind of private repository is a web server pointed at a directory full of static files. You can use a file:/// URL in your :repositories to deploy that way if the directory is local to the machine on which Leiningen is running.
SCP
If you already have a server set up with your SSH public keys, the scp transport is a simple way to publish and consume private dependencies. Place the following inside defproject:
Then place the following outside the defproject:
It's also possible to deploy to a repository using the scp transport and consume from it over http if you set up nginx or something similar to serve the repository directory over HTTP.
N.B. SCP deploys to Clojars are no longer supported
Original source is here https://github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md