赞
踩
maven plugin 开发: https://maven.apache.org/plugin-developers/index.html
“Maven” is really just a core framework for a collection of Maven Plugins. In other words, plugins are where much of the real action is performed, plugins are used to: create jar files, create war files, compile code, unit test code, create project documentation, and on and on. Almost any action that you can think of performing on a project is implemented as a Maven plugin.
plugin的作用
A Mojo is really just a goal in Maven, and plug-ins consist of any number of goals (Mojos). Mojos can be defined as annotated Java classes or Beanshell script. A Mojo specifies metadata about a goal: a goal name, which phase of the lifecycle it fits into, and the parameters it is expecting.
MOJO is a play on POJO (Plain-old-Java-object), substituting “Maven” for “Plain”. Mojo is also an interesting word (see definition). From Wikipedia, a “mojo” is defined as: “…a small bag worn by a person under the clothes (also known as a mojo hand). Such bags were thought to have supernatural powers, such as protecting from evil, bringing good luck, etc.”
mojo理解为一个执行目标,maven本身就是很多mojo组成的。mojo实现plugin,让用户自已在compile
,process-classed
,test
,package
,install
, deploy
等阶段实现特定的执行逻辑
maven plugin 的几个标准阶段
阶段 | 含义 |
---|---|
compile | Compiles the Java code for the plugin |
process-classes | Extracts data to build the plugin descriptor |
test | Runs the plugin’s unit tests |
package | Builds the plugin jar |
install | Installs the plugin jar in the local repository |
deploy | Deploys the plugin jar to the remote repository |
@Mojo的使用参考:https://maven.apache.org/developers/mojo-api-specification.html#The_Descriptor_and_Annotations
如下就能简单的定义一个plugin的逻辑
package sample.plugin; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; /** * Says "Hi" to the user. * */ @Mojo( name = "sayhi") public class GreetingMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info( "Hello, world." ); } }
plugin的pom依赖
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-plugin-api -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugin-tools/maven-plugin-annotations -->
<dependency>
<groupId
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。