简体   繁体   English

leiningen - 如何为本地jar添加依赖项?

[英]leiningen - how to add dependencies for local jars?

I want to use leiningen to build and develop my clojure project. 我想用leiningen来构建和开发我的clojure项目。 Is there a way to modify project.clj to tell it to pick some jars from local directories? 有没有办法修改project.clj告诉它从本地目录中挑选一些罐子?

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? 另外,leiningen可以用来维护clojure项目的“lib”目录吗? If a bunch of my clojure projects share the same jars, I don't want to maintain a separate copy for each of them. 如果我的一堆clojure项目共享相同的jar,我不想为每个jar维护一个单独的副本。

Thanks 谢谢

Just use :resource-paths in your project.clj file. 只需在project.clj文件中使用:resource-paths I use it, eg to connect to Siebel servers. 我用它,例如连接到Siebel服务器。 Just created a resources directory in my project directory and copied the jar files in there. 刚刚在我的项目目录中创建了一个资源目录,并在那里复制了jar文件。 But of course you could use a more generic directory: 但是当然你可以使用更通用的目录:

(defproject test-project "0.1.0-SNAPSHOT"
:description "Blah blah blah"
...
:resource-paths ["resources/Siebel.jar" "resources/SiebelJI_enu.jar"])

Then from the lein repl I can create Siebel Data Bean instances, eg 然后从lein repl我可以创建Siebel数据Bean实例,例如

(def sbl (com.siebel.data.SiebelDataBean.))
(.login sbl "siebelServer" "user" "password")
...

If you have a newer Java version you can of course use wildcards in your path specification like this for a more general directory: 如果你有一个较新的Java版本,你当然可以在你的路径规范中使用通配符,这样更通用的目录:

:resource-paths ["/tmp/SiebelJars/*"]
  1. Create a directory in the project: 在项目中创建一个目录:

    mkdir maven_repository

  2. Add local jars to this repository: 将本地jar添加到此存储库:

    For example, this command adds the jaad-0.8.3.jar file to the maven repository: 例如,此命令将jaad-0.8.3.jar文件添加到maven存储库:

    mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository

  3. Add the following to project.clj 将以下内容添加到project.clj

    :repositories {"local" "file:maven_repository"}

  4. Now a regular lein deps should work: 现在一个普通的lein deps应该工作:

    $ 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. 警告可以忽略,因为jar将被检入项目而不是从互联网上下载。

Original source: Using local JAR's with Leiningen (changed since copying) 原始来源: 使用Leiningen的本地JAR (自复制后更改)

You could put your private jars in lib/ and they'd be on the classpath for the purposes of lein swank and the like; 你可以将你的私人罐放在lib/并且为了lein swank之类的目的,他们会在类路径上; 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 with lein clean . 这似乎打败了使用依赖管理工具的重点,但如果你实际上并不想要管理这些依赖项,你可以将Leiningen视为“开源依赖管理工具”,也许要小心lein 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. 随着情况变得更加复杂 - 涉及的私人罐子数量越来越多,它们也在不断发展,您需要考虑一些版本信息--Arthur创建私有Maven回购的想法可能更合适。


(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.) (HR表示Leiningen特定的部分截止点...继续下面,了解Clojure土地中一般构建/依赖管理工具故事的信息,包括一些我认为在您的情况下可能非常方便的链接。)

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. 此外,到目前为止,关于哪个是Clojure的最佳构建工具的问题还没有达成普遍共识,而Leiningen虽然获得了大家的关注,但也在不断获得领域特征和润色 - 特别是,它尚未完成。 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." 以下是Pragmatic Bookshelf的“Programming Clojure”的作者Stuart Halloway的引用:“我的2c:Leiningen是重要的一步,但仍有很多工作要做。” 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? 对于完整的发布和一个非常有趣的讨论:在Clojure空间中构建工具等,请参阅Leiningen,Clojure和图书馆:我缺少什么? thread on the Clojure Google group. Clojure Google小组的主题。 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. 无论如何,Leiningen可能实际上还没有为一些复杂的场景准备好故事。 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 ; 如果您认为这可能适用于您的情况(我的意思是在您考虑私人回购的想法之后),这里有一些链接到基于maven的替代品,取自上面提到的线程: polyglot mavenclojure-maven-plugin ; this blog posting aims to be useful to people trying to use maven with Clojure. 这篇博文旨在对试图与Clojure使用maven的人有用。 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; 我记得,Meikel Brandmeyer(也是他在kotarak的在线句柄上的SO)使用Gradle(一个Groovy构建系统)和一个插件来容纳Clojure,称为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. 我自己从未尝试过,因为不知道关于Groovy的第一件事,但他声称用它做了一个非常好的建筑行为,我相信它与maven无关 - 这本身就是一个加号本身对于我们中的一些人 :-) :-)

I find lein pom; lein jar; lein install 我找到了lein pom; lein jar; lein install lein pom; lein jar; lein install lein pom; lein jar; lein install works well when developing libraries. lein pom; lein jar; lein install在开发库时运行良好。

Do this in the library being developed and your application requiring it will use it without any :repositories foo required. 在正在开发的库中执行此操作,并且您需要它的应用程序将使用它而不需要:repositories foo。


Alternatively, lein do pom, jar, install is slightly more concise. 或者, lein do pom, jar, install稍微简洁一点。


This allows calling the library like any other :dependencies [[project-name "version"]] 这允许像任何其他的一样调用库:dependencies [[project-name "version"]]

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. 我相信“正确”的方法是创建一个私有Maven存储库,以便您可以将jar存储在一个位置,所有分支等都将获取更改。 This may be overkill for what your doing. 对于你的所作所为,这可能有点过头了。 I'm curious if these is an easier way. 我很好奇这些是否更容易。

你可能想使用插件lein-localrepohttps//github.com/kumarshantanu/lein-localrepo

A recent development is Phil's s3-wagon-private plugin for Leiningen: https://github.com/technomancy/s3-wagon-private 最近的一项发展是Phil为Leiningen推出的s3-wagon-private插件: https//github.com/technomancy/s3-wagon-private

This should allow you to publish artifacts to a private remote repo. 这应该允许您将工件发布到专用远程仓库。

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 相反,我已经安装了一个本地存储库,并使用maven在本地存储库中安装jar文件,并将本地存储库添加到我的project.clj

In command line: 在命令行中:

mvn deploy:deploy-file -DgroupId=local -DartifactId=bar \
    -Dversion=1.0.0 -Dpackaging=jar -Dfile=bar.jar \
    -Durl=file:repo

And I write my project.clj like this: 我像这样编写我的project.clj:

(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [local/bar "1.0.0"]]
  :repositories {"project" "file:repo"})

Hope it helps. 希望能帮助到你。

[REFERENCE: https://gist.github.com/stuartsierra/3062743 ] [参考: https//gist.github.com/stuartsierra/3062743 ]

也许看一下之前的答案 ,我提供了一步一步的说明来设置项目的本地存储库(通过file://访问),您可以在其中安装您的jar。

尝试我的解决方案如何使用依赖项构建jar文件http://middlesphere-1.blogspot.ru/2014/06/how-to-make-jar-with-dependencies-using.html

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 最好的选择是设置一个私有的JFrog / Nexus工件并在那里部署你的快照/版本,然后在你的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. 静态HTTP最简单的私有存储库是指向充满静态文件的目录的Web服务器。 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. 如果目录是运行Leiningen的计算机的本地目录,则可以在:存储库中使用file:/// URL进行部署。

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. SCP如果您已经使用SSH公钥设置了服务器,则scp传输是一种发布和使用私有依赖项的简单方法。 Place the following inside defproject: 将以下内容放在defproject中:

:plugins [[org.apache.maven.wagon/wagon-ssh-external "2.6"]]
:repositories [["releases" "scp://somerepo.com/home/repo/"]]

Then place the following outside the defproject: 然后将以下内容放在defproject之外:

(cemerick.pomegranate.aether/register-wagon-factory!
 "scp" #(let [c (resolve 'org.apache.maven.wagon.providers.ssh.external.ScpExternalWagon)]
          (clojure.lang.Reflector/invokeConstructor c (into-array []))))

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. 如果您设置nginx或类似的东西通过HTTP提供存储库目录,也可以使用scp传输部署到存储库并通过http使用它。

NB SCP deploys to Clojars are no longer supported 不再支持NB部署到Clojars的NB

Original source is here https://github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md 原始来源在这里https://github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM