如何在一个命令行中下载特定的Maven工件? [英] How can I download a specific Maven artifact in one command line?

查看:136
本文介绍了如何在一个命令行中下载特定的Maven工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过install:install-file安装工件, 但是我该如何下载工件呢?

I can install an artifact by install:install-file, but how can I download an artifact?

例如:

mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST

推荐答案

您可以使用 maven依赖插件,它具有很好的 dependency:get 从2.1版开始的目标.不需要pom,一切都在命令行中进行.

You could use the maven dependency plugin which has a nice dependency:get goal since version 2.1. No need for a pom, everything happens on the command line.

要确保找到dependency:get目标,您需要明确告知maven使用版本2.1,即,您需要使用插件的完全限定名称,包括版本:

To make sure to find the dependency:get goal, you need to explicitly tell maven to use the version 2.1, i.e. you need to use the fully qualified name of the plugin, including the version:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
    -DrepoUrl=url \
    -Dartifact=groupId:artifactId:version

更新:对于较早版本的Maven(2.1之前的版本),可以通过强制使用Maven副本正常运行dependency:get(而不使用完全限定的名称和版本).给定版本的插件.

UPDATE: With older versions of Maven (prior to 2.1), it is possible to run dependency:get normally (without using the fully qualified name and version) by forcing your copy of maven to use a given version of a plugin.

这可以如下进行:

1.在~/.m2/settings.xml文件的<settings>元素内添加以下行:

1. Add the following line within the <settings> element of your ~/.m2/settings.xml file:

<usePluginRegistry>true</usePluginRegistry>

2.添加具有以下内容的文件~/.m2/plugin-registry.xml:

2. Add the file ~/.m2/plugin-registry.xml with the following contents:

<?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.实际上,根据插件注册表简介plugin-registry.xml的功能已经过重新设计(出于可移植性),并且 plugin注册表当前在Maven 2 中处于半休眠状态.因此,我认为我们现在必须使用长名称(当使用不带pom的插件时,这是dependency:get背后的想法).

But this doesn't seem to work anymore with maven 2.1/2.2. Actually, according to the Introduction to the Plugin Registry, features of the plugin-registry.xml have been redesigned (for portability) and the plugin registry is currently in a semi-dormant state within Maven 2. So I think we have to use the long name for now (when using the plugin without a pom, which is the idea behind dependency:get).

这篇关于如何在一个命令行中下载特定的Maven工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆