ToB企服应用市场:ToB评测及商务社交产业平台
标题:
Maven自定义插件的开发示例
[打印本页]
作者:
伤心客
时间:
2022-8-9 14:46
标题:
Maven自定义插件的开发示例
1、创建maven项目,配置相关依赖pom.xml
注意 maven-plugin
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wywtime.plugins</groupId>
<artifactId>bsmn-maven-plugin</artifactId>
<version>0.0.1</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
复制代码
2、创建AbstractMojo实现类
package com.wywtime.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.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@Mojo(name = "hello")
public class BsmnMavenHelloMojo extends AbstractMojo {
@Parameter
private String basedir;
@Parameter
private String name;
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("hello "+name+", this is bsmn's first plugin");
getLog().info("current basedir is:"+basedir);
}
}
复制代码
3、安装插件
mvn install
复制代码
发现通过idea工具install,与命令行有差异,是因为命令行用的是本地安装的maven
# 可通过如下指令来查看实际的配置
mvn help:effective-settings
复制代码
4、修改settings.xml
<pluginGroups>
<pluginGroup>com.wywtime.plugins</pluginGroup>
</pluginGroups>
复制代码
5、在新项目中引入插件
修改pom.xml
<build>
<plugins>
<plugin>
<groupId>com.wywtime.plugins</groupId>
<artifactId>bsmn-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<name>abc</name>
<basedir>${project.basedir}</basedir>
</configuration>
</plugin>
</plugins>
</build>
复制代码
6、执行指令
mvn bsmn:hello
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4