目前,我正在测试 Gradle 作为 Maven 的替代品。在我的项目中,有一些 3rd 方 jar,它们在任何 (Maven) 存储库中都不可用。我现在的问题是,我如何管理它以将这些 jar 安装到我的本地 .gradle 存储库中。 (如果可以的话,我不想使用本地Maven存储库,因为Gradle应该独立运行。)目前,我因为缺少jar而遇到很多异常。在 Maven 中,通过运行 install 命令非常简单。但是,我在 Google 上搜索类似于 Maven 安装命令的内容没有成功。有人有想法吗?
currently, I'm testing Gradle as an alternative to Maven. In my projects, there are some 3rd party jars, which aren't available in any (Maven) repositories. My problem is now, how could I manage it to install these jars into my local .gradle repository. (If it's possible, I don't want to use the local Maven repository, because Gradle should run independently.) At the moment, I get a lot of exceptions because of missing jars. In Maven, it's quite simple by running the install command. However, my Google search for something similar to the Maven install command wasn't successful. Has anybody an idea?
发布评论
评论(6)
您可以包含文件系统 JAR 依赖项,如下所示:
您可以更改编译/测试编译/等的运行时。
you can include your file system JAR dependencies as:
you may change runtime for compile/testCompile/etc..
Adam Murdoch 在邮件列表中给出了更全面的答案 http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle- repository-td1431953.html
截至 2010 年 4 月,没有简单的方法可以将新的 jarfile 添加到 ~/.gradle 存储库。目前正在研究这种情况是否有所改变。
截至 2014 年 10 月,情况仍然如此——因为 gradle 对你的 jarfile 进行了 md5 校验,所以你不能简单地下载它并将其放入 .gradle/caches 下的目录中,而 gradle 不会,就目前而言我可以告诉你,有任何任务可以让你获取本地文件并将该文件推送到其缓存。
A more comprehensive answer was given on a mailing list by Adam Murdoch at http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html
As of April 2010 there was no simple way to add a new jarfile to your ~/.gradle repository. Currently researching whether this has changed.
As of October 2014, this is still the case--because gradle does an md5 checksum of your jarfile, you can't simply download it and put it into a directory under .gradle/caches, and gradle doesn't, as far as I can tell, have any tasks which let you take a local file and push that file to its cache.
使用 Adam Murdoch 帖子中的选项 (1)(上面已链接:http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle- repository-td1431953.html)与 gradle-1.3 一起使用,效果很好!
这是他的评论:
Used option (1) out of Adam Murdoch post (already linked above: http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html) with gradle-1.3 and it works just nicely!
Here his comment:
也许我在阅读你的问题时遗漏了一些东西,假设你的 gradle 存储库是 flatDir 类型,你应该能够以 myjar-1.0.jar 的形式复制文件并将它们解析为版本 1.0 的 myjar 。
不知道为什么 Gradle 需要运行 Maven 才能访问本地 Maven 存储库。您只需定义 Maven 存储库即可,它应该可以解决依赖关系。如果需要,您可以使用 gradle upload 将 jar 推送到本地或远程 Maven 存储库。在这种情况下,它将执行maven。
Maybe I'm missing something from my reading of your question, assuming your gradle repo is of the flatDir type, you should be able to copy the files there in the form myjar-1.0.jar and resolve them as myjar of version 1.0.
Not sure why should it be necessary for Gradle to run maven in order to access a local maven repository. You can just define the maven repos and it should resolve dependencies. You can use
gradle upload
to push the jars local or remote maven repos if you need to. In that case, it will execute maven.简而言之:部署到存储库管理器。它可以是本地的,位于公司 LAN 上。
思考此类问题的一种完全不同的方式,特别是如果它经常发生的话,就是使用存储库管理器。有一些很棒的开源选项,例如 Artifactory、Nexus 或 Archiva。
假设您有一个来自某个可疑来源的 jar 文件,需要将其包含在您的构建中,直到您有机会重构它为止。存储库管理器允许您将文件上传到您自己的存储库,在本例中为 dubious-origin-UNKNOWN.jar
然后您的 build.gradle 看起来像这样:
使用它还有很多其他优点存储库管理器,例如缓存远程工件、从 scm 中删除工件、暂存版本、更细粒度的用户权限等等。
不利的一面是,您将添加一台服务器,该服务器会带来一些维护开销以保持构建运行。
我想这取决于你的项目的大小。
In short: deploy to repository manager. It can local, on company LAN.
An altogether different way of thinking about this type of problem, specially if it happens often, is to use a repository manager. There are some great open source options out there such as Artifactory, Nexus or Archiva.
Lets assume you have a jar file from some dubious origin that needs to be included in your build until you have the opportunity of refactoring it out. A repository manager would allow you to upload the file to your own repository as, for the sake of this example, dubious-origin-UNKNOWN.jar
Then your build.gradle would look something like this:
There are a lot of other advantages to using a repository manager such as caching of remote artifacts, remove artifacts from scm, staging releases, more granular user permissions, and so forth.
On the down side, you would be adding a server which carries some maintenance overhead to keep your builds running.
Depends on the size if your project, I suppose.
我认为这样的事情应该有效:
它对你有用吗?
I think something like this should work:
Does it work for you?