Can I download some files from http while maven lifecycle? any plugin?
Whenever you run build job, maven first try to find dependency from local repository. If it is not there, then, by default, maven will trigger the download from this central repository location. To override this default location, you can can make changes to your settings.
Download Plugin for Maven This is a plugin meant to help maven user to download different files on different protocol in part of maven build. For the first implementation, there will only be a goal that will help downloading a maven artifact from the command line.
When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.
Also note that Maven will download the jar to your local repository, and there's no sensible way (that I know of) to copy it to a local directory.
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:
<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 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.
Seems like wagon-maven-plugin from CodeHaus allows to download files over HTTP (though this is not is original goal).
Here is an example downloading 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With