简体   繁体   English

Maven 将多个 jars 导入本地仓库

[英]Maven import multiple jars to local repo

I am trying to export to the dependencies of my project using:我正在尝试使用以下方法导出到我的项目的依赖项:

mvn dependency:copy-dependencies -Dmdep.useRepositoryLayout=true -DoutputDirectory=c:\output

The result of this is a subset of my local maven repository containing some jars that only I have on my machine.这样做的结果是我本地 maven 存储库的一个子集,其中包含一些只有我的机器上才有的 jar。

I am trying to SHARE this subset of my local repository with my colleague.我正在尝试与我的同事共享我本地存储库的这个子集。

All I want is to send this folder structure so he can import it to this own local maven maven repository.我想要的只是发送此文件夹结构,以便他可以将其导入到这个自己的本地 maven Maven 存储库中。

We tried to copy these folders in his own local repository knowing this won't work.我们试图将这些文件夹复制到他自己的本地存储库中,但知道这行不通。

My question is there any way to tell maven to "index" these files that were copied in the directory?我的问题是有什么方法可以告诉 Maven 为目录中复制的这些文件“编制索引”?

There are descriptors next to these files and inside the META-INF folders that makes me believe that group-ids, artifact-ids and version could be resolved.这些文件旁边和 META-INF 文件夹中有描述符,这让我相信可以解析组 ID、工件 ID 和版本。

Is there a solution or a workaround for this?是否有解决方案或解决方法?

We could use mvn install:install-file for each individual jar, but there is too many.我们可以为每个单独的 jar 使用 mvn install:install-file,但是太多了。

Thank you very much, Peter非常感谢,彼得

So, there two solutions to your problem:因此,您的问题有两种解决方案:

  1. The real and standard solutions to share jars inside a company is to set up a Nexus or Artifactory server where you deploy your build artifacts to and which your colleague uses.在公司内部共享 jar 的真实标准解决方案是设置 Nexus 或 Artifactory 服务器,您可以在其中部署构建工件并供您的同事使用。 Actually, if you develop with Maven with more than two people in a company, I would always set up a Nexus/Artifactory.实际上,如果你在一个公司有两个以上的人使用 Maven 进行开发,我总是会建立一个 Nexus/Artifactory。 They are for free and easy to use.它们免费且易于使用。

  2. If you really want to go forward with your approach, you can give the whole directory to your colleague.如果你真的想继续你的方法,你可以把整个目录给你的同事。 Then you can put this directory as a repository into the settings.xml and use it.然后你可以把这个目录作为存储库放到settings.xml并使用它。 Repositories can be local directories, they need not be remote repositories.存储库可以是本地目录,它们不必是远程存储库。 See eg this answer https://stackoverflow.com/a/28762617/927493参见例如这个答案https://stackoverflow.com/a/28762617/927493

If you want a quick workaround, then you can make a copy of your entire repository and then remove the elements that you don't want to include.如果您想要快速解决方法,那么您可以制作整个存储库的副本,然后删除您不想包含的元素。 Compress the whole repository folder, pay special attention to include all the hidden files and send it.压缩整个存储库文件夹,特别注意包含所有隐藏文件并发送。

This way you will include not only the metainfos that are in the jar folders, but also other metainfos that are spreaded in other folders inside the repo.这样,您不仅会包含 jar 文件夹中的元信息,还会包含分布在 repo 内其他文件夹中的其他元信息。

Your colleague will need to use that repository instead of their own (althought I would make a backup until doublecheck everything works ok).您的同事将需要使用该存储库而不是他们自己的存储库(虽然我会进行备份,直到仔细检查一切正常)。 This way should work.这种方式应该有效。 The dependencies he had in it's own repo should be downloaded automatically again if needed, as long as he have access to remote repos.只要他有权访问远程存储库,他在自己的存储库中的依赖项应该会在需要时再次自动下载。

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

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