Maven: downloading files from url

后端 未结 6 1992
生来不讨喜
生来不讨喜 2020-12-02 14:08

Can I download some files from http while maven lifecycle? any plugin?

6条回答
  •  孤街浪徒
    2020-12-02 14:42

    If the file is a Maven dependency, you could use the Maven Dependency Plugin which has a get goal.

    For any file, you could use the Antrun plugin to call Ant's Get task.

    Another option would be the maven-download-plugin, it has been precisely created to facilitate this kind of things. It's not very actively developed and the documentation only mentions an artifact goal that does exactly the same thing as dependency:get but.. If you look at the sources, you'll see that is has a WGet mojo that will do the job.

    Use it like this in any POM:

    
      com.googlecode.maven-download-plugin
      download-maven-plugin
      1.3.0
      
        
          
          process-resources
          
            wget
          
          
            http://url/to/some/file
            foo.bar
            
            ${project.build.directory}
          
        
      
    
    

    Key benefits of this plugin are caching of the download and checking against a signature, such as MD5.

    Note that this answer has been heavily updated to reflect changes in the plugin as noted in the comments.

提交回复
热议问题