您可以基于 Ant 脚本编写 Maven 插件。
<project> ... <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-script-ant</artifactId> <version>2.2.1</version> </dependency> </dependencies> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.6.4</version> <dependencies> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-tools-ant</artifactId> <version>3.6.4</version> </dependency> </dependencies> </plugin> </plugins> </build> ... </project>
Ant 插件包含两个文件。如果你想创建一个touch
插件,你必须有:
src/main/scripts/touch.mojos.xml
: 包含 Mojo(s) 描述符信息,src/main/scripts/touch.build.xml
: 包含要执行的 Ant xml。<pluginMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/PLUGIN-METADATA/1.1.0" xsi:schemaLocation="http://maven.apache.org/PLUGIN-METADATA/1.1.0 http://maven.apache.org/xsd/plugin-metadata-1.1.0.xsd"> <mojos> <mojo> <!-- target name to call in ant script --> <call>touch-file</call> <!-- mojo goal name --> <goal>touch</goal> <parameters> <parameter> <name>name</name> <expression>${name}</expression> <required>true</required> <readonly>false</readonly> <type>java.lang.String</type> </parameter> </parameters> </mojo> </mojos> </pluginMetadata>
<project> <target name="touch-file"> <touch mkdirs="true" file="target/${name}"/> </target> </project>