用法
跑步
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/>
只有depends
Ant<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 插件的sourceRoot
和testSourceRoot
选项从 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 来避免不必要的开销。