将 Maven 工件传输下载到本地存储库

发布于 2024-11-09 17:12:36 字数 1549 浏览 5 评论 0 原文

我正在尝试将特定工件(及其所有依赖项)下载到计算机的本地存储库。

看起来使用 dependency:get 目标将是最好的选择,但尽管有文档,它似乎并没有真正获得传递依赖项。

这是一个示例,我尝试使用 dependency:get 下载 spring-core jar 及其所有依赖项。您会注意到 spring-core jar 是唯一下载的东西,尽管这是在清理本地存储库之后完成的。

$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.2:get -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:3.0.5.RELEASE -Dtransitive=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.2:get (default-cli) @ standalone-pom ---
Downloading: http://repo1.maven.org/maven2/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE.jar
Downloaded: http://repo1.maven.org/maven2/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE.jar (374 KB at 548.4 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.401s
[INFO] Finished at: Wed May 25 00:29:47 CDT 2011
[INFO] Final Memory: 7M/107M
[INFO] ------------------------------------------------------------------------



我的问题是:

  1. 这是 dependency:get 目标的错误吗?
  2. 如果不是,我做错了什么?
  3. 我可以使用任何替代方法来实现我最初设定的目标吗?

I am trying to download a specific artifact (and all of its dependencies) to a machine's local repository.

It would seem that using the dependency:get goal would be the best option for this, but despite the documentation it does not seem to actually get the transitive dependencies.

Here is an example where I have tried to use dependency:get to download the spring-core jar and all of its many dependencies. You'll notice that the spring-core jar is the only thing downloaded despite the fact that this was done after cleaning the local repository.

$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.2:get -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:3.0.5.RELEASE -Dtransitive=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.2:get (default-cli) @ standalone-pom ---
Downloading: http://repo1.maven.org/maven2/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE.jar
Downloaded: http://repo1.maven.org/maven2/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE.jar (374 KB at 548.4 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.401s
[INFO] Finished at: Wed May 25 00:29:47 CDT 2011
[INFO] Final Memory: 7M/107M
[INFO] ------------------------------------------------------------------------

My questions are:

  1. Is this a bug with the dependency:get goal?
  2. If not, what am I doing wrong?
  3. Are there any alternatives methods I could use to accomplish my initially stated goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-11-16 17:12:36

如果这是一次性或不定期发生的情况,最简单的方法是在 POM 中定义依赖项并运行 mvn package 或类似的方法来检索依赖项工件。如果您也想拥有源 jar,您也可以尝试 mvn dependency:sources

如果您想更频繁地执行此操作或作为流程的一部分,您可以考虑使用 Aether 直接为您检索依赖项。

如果您需要定期执行此操作以管理内部开发生态系统中的工件组,则另一种方法是使用 Nexus 的采购套件 用于检索依赖项并将其管理到您的存储库中。

If this is a one time or irregular occurrence for you, The simplest thing to do would be to define the dependency in a POM and run mvn package or similar to retrieve the dependency artifacts. You could also try mvn dependency:sources if you'd like to have the source jars too.

If this is something you want to do more regularly or as part of a process, you could look at using Aether directly to retrieve the dependencies for you.

Another approach if this is something you need to do regularly to manage groups of artifacts into your internal development ecosystem is to use Nexus' procurement suite to retrieve the dependencies and manage them into your repository.

冷清清 2024-11-16 17:12:36

您可能可以采用此解决方案

1) 按照您的描述下载工件(我使用版本 2.5.2 进行测试)

c:\test>mvn -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:2.5.2 -Dtransitive=true

2) 下载此工件的 pom (-Dpackaging=pom)

c:\test>mvn -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:2.5.2 -Dtransitive=true -Dpackaging=pom org.apache.maven.plugins:maven-dependency-plugin:2.2:get

3) 使用下载的pom 通过 dependency:copy-dependency gaol 复制所有依赖项,

c:\test>mvn -DoutputDirectory=C:/test/dependency -f C:/<path-to-repository>/org/springframework/spring-core/2.5.2/spring-core-2.5.2.pom dependency:copy-dependencies

您将在创建的项目中找到依赖项(包括 testoptional 范围!) c:\test\dependency 文件夹。要排除测试和可选范围,请使用 -DincludeScope=runtime。

您需要动态构建一些路径信息(例如,存储库中 pom 的路径)来设置此解决方案,并且还需要将工件本身及其依赖项放在一起,但它应该在脚本中工作,而无需生成特殊的 pom(这可能会更容易)。

You might can go with this solution

1) Download the artifact as you described (I tested with version 2.5.2)

c:\test>mvn -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:2.5.2 -Dtransitive=true

2) Download the pom (-Dpackaging=pom) of this artifact

c:\test>mvn -DrepoUrl=http://repo1.maven.org/maven2/ -Dartifact=org.springframework:spring-core:2.5.2 -Dtransitive=true -Dpackaging=pom org.apache.maven.plugins:maven-dependency-plugin:2.2:get

3) Use the downloaded pom to copy all dependencies via the dependency:copy-dependency gaol

c:\test>mvn -DoutputDirectory=C:/test/dependency -f C:/<path-to-repository>/org/springframework/spring-core/2.5.2/spring-core-2.5.2.pom dependency:copy-dependencies

You will find the dependencies (including test and optional scope!) in the created c:\test\dependency folder. To exclude test and optional scope use -DincludeScope=runtime.

You need to dynamically build some path information (e.g. path to the pom in your repository) to set up this solution and also need to bring the artifact itself together with its dependencies but it should work in a script without generating a special pom (which might be easier).

篱下浅笙歌 2024-11-16 17:12:36

问题#1(这是依赖项:获取目标的错误吗?)的答案似乎是肯定的。截至 2011 年 5 月 25 日,问题 MDEP-308 仍未解决。

It would appear the answer to question #1 (Is this a bug with the dependency:get goal?) is yes. As of 5/25/2011 issue MDEP-308 is still unresolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文