maven,maven-antrun-plugin,通过属性进行参数化

时间:2016-04-16 18:14:07

标签: maven ant maven-antrun-plugin

我正在构建maven项目,这些项目都需要在构建过程中下载,解压缩并移动多个文件。因此我正在使用通过maven-antrun-plugin运行的ant脚本。由于此工作流需要在多个项目中执行,我想将ant脚本放在父pom.xml中,并且只在子pom.xml文件中进行一些参数化,我在其中定义实际文件下载(这是不同的,因为我构建了特定于平台的项目)。

应该转到父pom.xml的蚂蚁脚本看起来像这样:

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

上面脚本中唯一可变的部分是ant get任务。如果我可以简单地将URL列表作为maven properties下载到具体子项目中,那就太好了。但是,由于具有不同数量的URL,我需要一些“集合”属性,这显然不存在。相反,我尝试传递以逗号分隔的URL列表:

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

...然后使用ant:

中的for任务拆分列表
<for param="url" list="${urls.to.download}">
    <sequential>
        <get dest="${directory.download}">
            <url>${url}</url>
        </get>
    </sequential>
</for>

然而这失败了,因为for似乎不支持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.

是否有任何替代方法或方法可以使for任务有效?

0 个答案:

没有答案