使用Maven将依赖项下载到命令行上的目录
我需要将项目的所有传递依赖项下载到命令行上的目录,而没有pom.xml文件或其他脚本。理想情况下,我可以使用一个或两个命令执行此操作。据我所知,这至少是使用mvn的两步过程。
I need to download all transitive dependencies of a project to a directory on the command line without having a pom.xml file or other script. Ideally I would be able to do this with one or two commands. From what I can tell, this is at least a 2 step process with mvn.
- 将依赖项下载到本地存储库
- 将依赖项复制到lib目录
要获取我运行的依赖项
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.6:get -DgroupId=org.jclouds.provider -DartifactId=rackspace-cloudservers-us -Dversion=1.5.8
哪个效果很好。不幸的是,dest param对我没有帮助,因为它不会将所有传递依赖项放在dest中。
Which works great. Unfortunately the dest param doesn't help me as it won't put all transitive dependencies in the dest.
所以现在我需要复制那个JAR文件及其所有的传递依赖到我的lib目录。我知道这部分已经在StackOverflow上被问了很多次,但是我的工作没有任何效果。我已尝试过以下内容。
So now I need to copy that JAR file and all of its transitive dependencies into my lib directory. I know this part has been asked many time on StackOverflow but nothing has worked for my yet. I've tried the following.
$ mvn dependency:copy-dependencies ...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies (default-cli): Goal requires a project to execute but there is no POM in this directory
和
$ mvn dependency:copy ...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:copy (default-cli): Goal requires a project to execute but there is no POM in this directory
通过阅读StackOverflow上的文档和其他答案来获取复制依赖和复制我想我会能够在没有pom.xml的情况下从命令行使用它们,但是mvn似乎需要一个。我的Maven版本是Apache Maven 3.0.4(r1232337; 2012-01-17 02:44:56-0600)。
From reading the documentation and other answers here on StackOverflow for copy-dependencies and copy I thought I would be able to use them from the command line without a pom.xml but mvn seems to need one. My Maven version is Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600).
任何人都可以给我一个复制传递的例子使用没有pom.xml的mvn的依赖关系?
Can anyone give me an example of copying transitive dependencies using mvn without a pom.xml?
有没有更好的方法来做我在这里尝试完成的事情?
Is there a better way to do what I'm trying accomplish here?
第一个命令几乎可以满足您的需求 - 相关依赖项的POM。一旦你有了这个,你就不需要另外一个项目POM来运行 copy:dependencies
:
The first command almost gets you what you need - the POM of the dependency in question. Once you have that, you should not need a further project POM to run copy:dependencies
:
这是一个例子:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:get -DgroupId=org.jclouds.provider -DartifactId=rackspace-cloudservers-us -Dversion=1.5.8 -Dtype=pom
mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:copy-dependencies -f /path/to/m2/repo/org/jclouds/provider/rackspace-cloudservers-us/1.5.8/rackspace-cloudservers-us-1.5.8.pom -DoutputDirectory=/path/to/target/dir/don't/use/.
正如 Everett Toews ,您可以使用 copy:dependencies
以进一步细化下载的内容,例如通过添加 -DexcludeTypes = test-jar
来过滤掉测试JAR。
As pointed out by Everett Toews, you can use additional options of copy:dependencies
to further refine what's downloaded, e.g. by adding -DexcludeTypes=test-jar
to filter out the test JARs.