Maven: downloading files from a url

Is it possible to download some files from http during the maven life cycle? any plugin?

+41
maven-2 get
Apr 30 '10 at 1:29
source share
6 answers

If the file is Maven dependent, you can use the Maven Dependency Plugin , which has get .

For any file, you can use the Antrun plugin to call Ant Get the task .

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

Use this as in any POM:

 <plugin> <groupId>com.googlecode.maven-download-plugin</groupId> <artifactId>download-maven-plugin</artifactId> <version>1.3.0</version> <executions> <execution> <!-- the wget goal actually binds itself to this phase by default --> <phase>process-resources</phase> <goals> <goal>wget</goal> </goals> <configuration> <url>http://url/to/some/file</url> <outputFileName>foo.bar</outputFileName> <!-- default target location, just to demonstrate the parameter --> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </execution> </executions> </plugin> 

Key benefits of this plugin are download caching and signature verification, such as MD5.

Please note that this answer has been heavily updated to reflect changes in the plugin as indicated in the comments.

+40
Apr 30 '10 at 2:29
source share

It seems that the wagon-maven-plugin from CodeHaus allows uploading files via HTTP (although this is not the original purpose).

Here is an example of loading GlassFish zip before integration tests:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <id>download-glassfish</id> <phase>pre-integration-test</phase> <goals> <goal>download-single</goal> </goals> <configuration> <url>http://download.java.net</url> <fromFile>glassfish/3.1/release/glassfish-3.1.zip</fromFile> <toDir>${project.build.directory}/glassfish</toDir> </configuration> </execution> </executions> </plugin> 
+21
Apr 22 2018-11-11T00:
source share

Maven-antrun-plugin is a more direct solution:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>download-files</id> <phase>prepare-package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <!-- download file --> <get src="http://url/to/some/file" dest="${project.build.directory}/downloads/" verbose="false" usetimestamp="true"/> </target> </configuration> </execution> </executions> </plugin> 
+13
Jul 23 '13 at 20:26
source share

I would like to add a few things about loading-maven-plugin:

  • The project is now hosted on GitHub https://github.com/maven-download-plugin/maven-download-plugin
  • Its releases are available on Maven Central, and SNAPSHOT is available in the oss.sonatype.org snapshot repository.
  • Compared to the other offers mentioned here, the download-maven plugin adds the following interesting feature: file caching (to avoid reloading large files) and signature verification to ensure that the download received the correct bits.
+11
Oct 03 '13 at 6:36 on
source share

If available, wget can be used directly with exec-maven-plugin :

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>wget</executable> <arguments> <argument>http://example.com/file.zip</argument> <argument>destination.zip</argument> </arguments> </configuration> </plugin> 
0
Jan 7 '14 at 10:47
source share

You can use the download-single target in the wagon plugin. Here is an example of loading an HTML page (note that the URL should be divided into the URL of the "directory" and "file name")

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <phase>validate</phase> <goals><goal>download-single</goal></goals> <configuration> <url>http://www.mojohaus.org/wagon-maven-plugin</url> <fromFile>download-single-mojo.html</fromFile> <toFile>[my dir]/mojo-help.html</toFile> </configuration> </execution> </executions> </plugin> 
0
Nov 13 '16 at 2:06
source share



All Articles