创建plugin模块
<groupId>com.houzw.demo</groupId>
<artifactId>hzwcolatest-plugin</artifactId>
<!-- 打包类型为maven-plugin -->
<packaging>maven-plugin</packaging>
<dependencies>
<!-- 添加依赖 -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5.2</version>
</dependency>
</dependencies>
<!-- 添加插件 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5.2</version>
</plugin>
</plugins>
</build>
编写插件代码
@Mojo(name="hzwtest")
public class HzwTestMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
System.out.println("hzwtest plugin start");
System.out.println("hzwtest plugin......");
System.out.println("hzwtest plugin end");
}
}
使用
<plugin>
<groupId>com.houzw.demo</groupId>
<artifactId>hzwcolatest-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<!-- 绑定执行阶段 --->
<phase>clean</phase>
<goals>
<!-- 指定执行目标Mojo -->
<goal>hzwtest</goal>
</goals>
</execution>
</executions>
</plugin>
执行mvn clean
时会执行指定Mojo,
或手动执行目标mvn hzwcolatest:hzwtest