用法

跑步

maven-antrun-plugin 只有一个目标,运行

这允许 Maven 运行 Ant 任务。为此,必须有一个现有的项目并且 maven-antrun-plugin 必须配置其<target>标签(尽管它仍然会在没有<target>标签的情况下执行,但它不会做任何事情)。下面是maven-antrun-pluginpom.xml的模板。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <target>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

此外,您可以通过复制<execution/>部分并指定新阶段来将脚本添加到每个生命周期阶段。

最终,您可以在<target/>标记中指定一些 Ant <target/>属性。只有Ant <target/>中的depends属性没有被包装。

[...]
<configuration>
  <target name="The name of the target"
    if="The name of the property that must be set in order for this task"
    unless="The name of the property that must NOT be set in order for this task"
    description="A short description of this target's function">

    <!--
      Place any Ant task here. You can add anything
      you can add between <target> and </target> in a
      build.xml.
    -->

  </target>
<configuration>
[...]

其他源目录

如果您的 ant 任务生成需要添加到构建中的其他源代码,您可以使用build-helper-maven-plugin。antrun 插件的 sourceRoot 和 testSourceRoot 选项已被弃用。

使用 Maven 属性

maven 可用的所有属性在目标配置中也可用。但是,您可能希望使用ant任务调用外部 Ant 构建脚本。为避免名称冲突,仅将一部分属性传递给外部 Ant 构建。这些包括在 POM 的属性部分中定义的所有属性。它还包括一些常用 Maven 属性的前缀版本。

  maven.project.groupId
  maven.project.artifactId
  maven.project.name
  etc.

如果您要使用的 maven 属性在外部文件中不可用,则必须在调用ant之前重新定义该属性。

  <property name="maven.project.url" value="${project.url}"/>
  <ant antfile="build.xml"/>

Ant 表达式到 Maven 表达式的映射

一些 Ant 表达式在 Maven 中有它们各自的对应项。因此,可以简单地调用相应的 Maven 表达式,而不是使用 maven-antrun-plugin 来避免不必要的开销。

蚂蚁表情Maven 表达式
内置任务
蚂蚁maven-antrun-插件
蚂蚁呼叫maven-antrun-插件
可用的简介
B解压缩2maven-程序集插件
BZip2maven-程序集插件
修改maven-程序集插件
健康)状况简介
复制Maven 资源插件
依赖集maven 依赖插件
耳朵maven-ear-插件
筛选maven-resources-plugin 注意:过滤器使用 @...@ 标记,而 maven-resources-plugin 使用 $ ...标记
修复CRLFMaven 资源插件
密钥maven-jar-插件
G解压缩maven-程序集插件
压缩包maven-程序集插件
maven-jar-插件
Javacmaven 编译器插件
Javadoc/Javadoc2maven-javadoc-插件
加载属性Maven 资源插件
显现maven-jar-插件
财产Maven 资源插件
代替maven-resources-plugin 注意:Replace 可以指定其令牌,而 maven-resources-plugin 使用 $ ...令牌
柏油maven-程序集插件
解开maven-程序集插件
解压maven-程序集插件
温华maven-程序集插件
解压maven-程序集插件
战争Maven 战争插件
压缩maven-程序集插件
可选任务
蚂蚁maven-antlr-插件
依靠maven 依赖插件
EJB 任务maven-ejb-插件
FTPmaven-deploy-plugin 注意:maven-deploy-plugin 只能部署到 FTP
JavaCCmaven 编译器插件
JJDocmaven 编译器插件
JJ树maven 编译器插件
JUnitmaven-surefire-插件
JUnitReportmaven-surefire-report-plugin
服务器部署Maven 部署插件
集代理Maven 部署插件
翻译maven-resources-plugin 注意:Translate 可以指定自己的标记,并且可以有不同的编码方案来读写文件。然而,maven-resources-plugin 仅使用 $ ...注释并且只有一种用于读写的编码方案