How can I download a specific Maven artifact in one command line?

前端 未结 11 947
太阳男子
太阳男子 2020-11-28 01:05

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

For example:

mvn download:download-file -Dgroup         


        
11条回答
  •  生来不讨喜
    2020-11-28 01:32

    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.

    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
    

    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.

    This can be done as follows:

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

    true
    

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

    
    
      
        
          org.apache.maven.plugins
          maven-dependency-plugin
          2.1
          
        
      
    
    

    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).

提交回复
热议问题