I'm building maven projects which all need to download, unzip and move several files during the build process. Therefore I'm using an ant script run via maven-antrun-plugin
. As this workflow needs to be executed in multiple projects, I would like to place the ant script in a parent pom.xml
and only do some parametrization in the child pom.xml
files, where I define the actual files to be downloaded (which are different, because I build platform-specific projects).
The ant script which should go to the parent pom.xml
looks something like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${directory.download}"/>
<get dest="${directory.download}">
<!--
this part should be variable and contains
different number of URLs in each child project
-->
<url url="http://example.com/binary1-win64.zip"/>
<url url="http://example.com/binary2-win64.zip"/>
<url url="http://example.com/binary3-win64.zip"/>
</get>
<!-- lots of further tasks, such as unzip, rename, etc. -->
</target>
</configuration>
</execution>
</executions>
</plugin>
The only variable part in above's script is the ant get
task. It would be nice, if I could simply pass the list of URLs to download as maven properties
in the concrete child projects. As a have a varying number of URLs however, I would need some "collection" property, which obviously does not exist. Instead, I tried passing a comma-separated list of URLs:
<properties>
<urls.to.download>http://example.com/binary1-win64.zip,http://example.com/binary2-win64.zip,http://example.com/binary3-win64.zip</urls.to.download>
</properties>
… and then split the list using a for
task in ant:
<for param="url" list="${urls.to.download}">
<sequential>
<get dest="${directory.download}">
<url>${url}</url>
</get>
</sequential>
</for>
This however fails, because the for
task does not seem to be supported by the maven-antrun-plugin
:
An Ant BuildException has occured: Problem: failed to create task or type for
[ERROR] Cause: The name is undefined.
[ERROR] Action: Check the spelling.
[ERROR] Action: Check that any custom tasks/types have been declared.
[ERROR] Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Are there any alternative approaches or a way, to make the for
task work?