我可以通过 install:install-file
安装工件,
但我怎样才能下载工件呢?
例如:
mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST
最佳答案
您可以使用maven dependency plugin其中有一个不错的 dependency:get
自 2.1 版本以来的目标。不需要 pom,一切都在命令行上发生。
确保找到dependency:get
目标,您需要明确告诉maven使用版本2.1,即您需要使用插件的完全限定名称,包括版本:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=url \
-Dartifact=groupId:artifactId:version
更新:使用旧版本的 Maven(2.1 之前),可以运行 dependency:get
通常(不使用完全限定名称和版本)通过强制您的 Maven 副本使用插件的给定版本。
这可以按如下方式完成:
<强>1。在 <settings>
中添加以下行您的元素~/.m2/settings.xml
文件:
<usePluginRegistry>true</usePluginRegistry>
<强>2。添加文件~/.m2/plugin-registry.xml
包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<pluginRegistry xsi:schemaLocation="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0 http://maven.apache.org/xsd/plugin-registry-1.0.0.xsd"
xmlns="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<useVersion>2.1</useVersion>
<rejectedVersions/>
</plugin>
</plugins>
</pluginRegistry>
但这似乎不再适用于 maven 2.1/2.2。实际上,根据Introduction to the Plugin Registry , plugin-registry.xml
的特点已经重新设计(为了可移植性),并且插件注册表目前在 Maven 2 中处于半休眠状态。所以我认为我们现在必须使用长名称(当使用没有 pom 的插件时,这就是 dependency:get
背后的想法)。
关于maven-2 - 如何在一个命令行中下载特定的 Maven 工件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1895492/