如何使用 Maven 调用 Ant Builts


How do I call Ant Builts using Maven

我有许多使用 ANT 运行的 php 项目的子模块 [它只是复制文件并运行 SQL]。

现在我需要实现 Maven 来处理未来的单元测试 + [Maven 是我们未来需要使用的最佳工具。

我已经在Eclipse中安装了Maven for php。我在IDE本身中使用Maven创建了一个新项目。我也可以运行该项目。[我是Maven的菜鸟,但对ANTs很好]

现在我想使用 Maven 项目调用这些子模块 ANT 的 xml。有 ANT RUN 可以为 maven 解决问题,但我无法:

  • 弄清楚如何在 Maven 项目之外引用模块的ANT xml
  • 蚂蚁只是链接XML就可以完成这项工作吗?还是需要更多依赖项?
使用

Maven ant runner 插件调用 ANT 逻辑,使用 ANT 的 subant 任务

$ tree
.
|-- pom.xml
`-- src
    `-- main
        `-- ant
            |-- module1
            |   `-- build.xml
            `-- module2
                `-- build.xml
5 directories, 3 files

绒球.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myspotontheweb.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <configuration>
                            <target>
                                <property name="src.dir" location="${project.build.directory}/../src"/>
                                <subant>
                                    <fileset dir="${src.dir}" includes="**/build.xml"/>
                                </subant>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

ANT 配置为在 Maven 构建的"编译"阶段运行。ANT 逻辑使用子任务来运行外部 ANT 逻辑。

运行示例

$ mvn compile
..    
..
[INFO] --- maven-antrun-plugin:1.7:run (default) @ demo ---
[INFO] Executing tasks
main:
main:
     [echo] module1: hello world
main:
     [echo] module2: hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.394s
[INFO] Finished at: Fri Apr 27 20:25:35 IST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------

您可以简单地在 Maven 的 Ant Run 插件的目标配置元素中使用 ant 任务。