自定义流程
1.新建maven项目
2.修改pom文件的打包方式(packaging=maven-plugin)
3.引入依赖
maven-plugin-api包
maven-plugin-annotations包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxxxxx</groupId>
<artifactId>xxx-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</project>
4.编写执行类,继承AbstractMojo,重写execute方法
@Mojo(name="printf",defaultPhase = LifecyclePhase.CLEAN)
public class MyMojo extends AbstractMojo
{
@Parameter
private String name;
public void execute() throws MojoExecutionException {
System.out.println(" ---------->>你好, " + name);
}
}
5.执行install
6.在其他项目引用
<build>
<plugins>
<plugin>
<groupId>xxxxxx</groupId>
<artifactId>xxx-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
7.执行mvn xxx:printf
配置
<plugin>
<groupId>com.test.maven</groupId>
<artifactId>my-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<!-- 执行目标 -->
<goal>printf</goal>
</goals>
<phase>clean</phase>
</execution>
</executions>
<!-- 这里对应的test节点,就是对应的自定义组件中,参数名 里面的值就是要注入的值,使用场景是,当需要注入目标项目的相对路径或者项目名称等等一些信息 -->
<configuration>
<name>peter</name>
</configuration>
</plugin>