多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] # 简介 插件要挂载才能运行 必须要导入这2个依赖 ~~~ <groupId>com.jdxia</groupId> <artifactId>chajian-plugin</artifactId> <version>1.0-SNAPSHOT</version> <packaging>maven-plugin</packaging> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>3.5.0</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>3.5</version> <scope>provided</scope> </dependency> </dependencies> ~~~ 然后创建个类 ~~~ @Mojo(name = "chajianABC", defaultPhase = LifecyclePhase.PACKAGE) public class Chajian extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { System.out.println("-------自定义插件---"); } } ~~~ 然后使用 ~~~ <plugin> <groupId>com.jdxia</groupId> <artifactId>chajian-plugin</artifactId> <version>1.0-SNAPSHOT</version> <executions> <execution> <phase>package</phase> <goals> <goal>chajianABC</goal> </goals> </execution> </executions> </plugin> ~~~ # 传参数 ~~~ <plugin> <groupId>com.jdxia</groupId> <artifactId>chajian-plugin</artifactId> <version>1.0-SNAPSHOT</version> <configuration> <msg>this is a message!</msg> <options> <option>one</option> <option>two</option> </options> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>chajianABC</goal> </goals> </execution> </executions> </plugin> ~~~ 创建个类 ~~~ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import java.util.List; @Mojo(name = "chajianABC", defaultPhase = LifecyclePhase.PACKAGE) public class Chajian extends AbstractMojo { @Parameter private String msg; @Parameter private List<String> options; //读取maven自带的属性 命令mvn install -Dargs=123 @Parameter(property = "args") private String args; @Override public void execute() throws MojoExecutionException, MojoFailureException { System.out.println("-------自定义插件---" + msg); System.out.println("-------自定义插件---" + options); } } ~~~ 写完要`mvn install`下 例子: [https://maven.apache.org/guides/plugin/guide-java-plugin-development.html](https://maven.apache.org/guides/plugin/guide-java-plugin-development.html)