我正在尝试将特定工件(及其所有依赖项)下载到计算机的本地存储库。
看起来使用 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] ------------------------------------------------------------------------
我的问题是:
- 这是
dependency:get
目标的错误吗?
- 如果不是,我做错了什么?
- 我可以使用任何替代方法来实现我最初设定的目标吗?
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:
- Is this a bug with the
dependency:get
goal?
- If not, what am I doing wrong?
- Are there any alternatives methods I could use to accomplish my initially stated goal?
发布评论
评论(3)
如果这是一次性或不定期发生的情况,最简单的方法是在 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 trymvn 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.
您可能可以采用此解决方案
1) 按照您的描述下载工件(我使用版本 2.5.2 进行测试)
2) 下载此工件的 pom (
-Dpackaging=pom
)3) 使用下载的pom 通过
dependency:copy-dependency
gaol 复制所有依赖项,您将在创建的项目中找到依赖项(包括
test
和optional
范围!)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)
2) Download the pom (
-Dpackaging=pom
) of this artifact3) Use the downloaded pom to copy all dependencies via the
dependency:copy-dependency
gaolYou will find the dependencies (including
test
andoptional
scope!) in the createdc:\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).
问题#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.