用法

跑步

maven-antrun-plugin 只有一个目标,run.

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

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.1.0-SNAPSHOT</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/>部分并指定新阶段来为每个生命周期阶段添加脚本。

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

[...]
<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 插件的sourceRoottestSourceRoot选项从 3.0.0 版开始被删除。

使用 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 表达式
内置任务
Ant maven-antrun-plugin
AntCall maven-antrun-plugin
Available profiles
BUnzip2 maven-assembly-plugin
BZip2 maven-assembly-plugin
Chmod maven-assembly-plugin
Condition profiles
Copy maven-resources-plugin
Dependset maven-dependency-plugin
Ear maven-ear-plugin
Filter maven-resources-plugin 注意:过滤器使用 @...@ 标记,而 maven-resources-plugin 使用 $ ...标记
FixCRLF maven-resources-plugin
GenKey maven-jar-plugin
GUnzip maven-assembly-plugin
GZip maven-assembly-plugin
Jar maven-jar-plugin
Javac maven-compiler-plugin
Javadoc/Javadoc2 maven-javadoc-plugin
LoadProperties maven-resources-plugin
Manifest maven-jar-plugin
Property maven-resources-plugin
Replace maven-resources-plugin 注意:替换可以指定它的令牌,而 maven-resources-plugin 使用 $ ...令牌
Tar maven-assembly-plugin
Unjar maven-assembly-plugin
Untar maven-assembly-plugin
Unwar maven-assembly-plugin
Unzip maven-assembly-plugin
War maven-war-plugin
Zip maven-assembly-plugin
可选任务
Antlr maven-antlr-plugin
Depend maven-dependency-plugin
EJB Tasks maven-ejb-plugin
FTP maven-deploy-plugin 注意:maven-deploy-plugin 只能部署到 FTP
JavaCC maven-compiler-plugin
JJDoc maven-compiler-plugin
JJTree maven-compiler-plugin
JUnit maven-surefire-plugin
JUnitReport maven-surefire-report-plugin
ServerDeploy maven-deploy-plugin
Setproxy maven-deploy-plugin
Translate maven-resources-plugin 注意:Translate 可以指定自己的标记,并且可以有不同的编码方案来读写文件。然而,maven-resources-plugin 仅使用 $ ...注释并且只有一种用于读写的编码方案