maven-antrun-plugin 只有一个目标,运行。
这允许 Maven 2 运行 Ant 任务。为此,必须有一个现有的项目并且 maven-antrun-plugin 必须配置其<tasks>标签(尽管它仍然会在没有<tasks>标签的情况下执行,但它不会做任何事情)。下面是maven-antrun-plugin的pom.xml的模板。
<project> [...] <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase> <!-- a lifecycle phase --> </phase> <configuration> <tasks> <!-- Place any Ant task here. You can add anything you can add between <target> and </target> in a build.xml. --> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project>
此外,您可以通过复制<execution/>部分并指定新阶段来将脚本添加到每个生命周期阶段。
最终,您可以在<tasks/>标记中指定一些 Ant <target/>属性。只有Ant <target/>中的depends属性没有被包装。
[...] <configuration> <tasks name="The name of the tasks" 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. --> </tasks> <configuration> [...]
下面你可以看到如何表明 Ant 已经生成了更多需要包含在编译阶段的 java 源代码。请注意,编译阶段遵循生命周期中的generate-sources阶段。
<project> [...] <build> <plugins> [...] <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <configuration> <tasks> <!-- Place any Ant task here. You can add anything you can add between <target> and </target> in a build.xml. --> </tasks> <sourceRoot> ${project.build.directory}/generated-sources/main/java </sourceRoot> <testSourceRoot> ${project.build.directory}/generated-sources/test/java </testSourceRoot> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project>
当然,您可以放置您喜欢的任何文件夹。上面示例中的文件夹很方便,因为它们在您清理时会被删除,因为它们位于构建目录中(默认情况下,“目标”)。
<sourceRoot/>将单个文件夹添加到使用程序源代码(compile)编译的文件夹列表中。
<testSourceRoot/>将单个文件夹添加到使用测试源代码 ( test-compile ) 编译的文件夹列表中。
一些 Ant 表达式在 Maven 中有它们各自的对应项。因此,可以简单地调用相应的 Maven 表达式,而不是使用 maven-antrun-plugin 来避免不必要的开销。