14

build.xml是否可以使用 Maven执行脚本?

这个脚本检查了我所有的项目和子项目,我刚刚习惯了使用 maven,以前并没有真正使用过太多的 ant,我知道 ant 可以与 Maven 一起使用。所以我的问题是:如何?

4

2 回答 2

10

我真的不是这种方法的忠实拥护者(使用 Ant 或 Maven,但不是混蛋),但您可以将外部build.xmlMaven AntRun 插件一起使用:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <configuration>
          <tasks>
            <taskdef resource="net/sf/antcontrib/antcontrib.properties"
              classpathref="maven.plugin.classpath" />
            <ant antfile="${basedir}/build.xml">
              <target name="test"/>
            </ant>
          </tasks>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

然后运行(如果你想将 AntRun 插件绑定到生命周期阶段,mvn antrun:run或者将配置放在里面,请参阅使用页面)。execution

更新:如果您使用来自 ant-contrib 的东西,则需要将其声明为插件的依赖项。我已经更新了插件配置以反映这一点。另请注意taskdef我添加的元素(但我不确定您是否需要该classpathref属性)。

于 2010-05-12T09:58:12.817 回答
0

您可以通过Maven-Ant Plugin执行 ant 脚本,但是为什么需要 Ant 来检查您的项目呢?您没有将子项目组织在同一棵树中吗?

于 2010-05-12T08:53:57.130 回答