pom.xml
<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.wurd</groupId>
<artifactId>wu_m</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<type>jar</type>
<version>2.0.6</version>
</dependency>
</dependencies>
</project>
继承AbstractMojo
package com.wurd.plugins.test;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
public class TestMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
System.out.println("#####");
System.out.println("do something");
System.out.println("#####");
}
}
plugin.xml(放在META-INF/maven下边)
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<name>test plugin</name>
<description>test plugin</description>
<groupId>com.wurd</groupId>
<artifactId>wu_m</artifactId>
<version>0.1</version>
<goalPrefix>test</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>test</goal>
<description>test plugin-test</description>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<implementation>com.wurd.plugins.test.TestMojo</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>true</threadSafe>
</mojo>
</mojos>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<type>jar</type>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<type>jar</type>
<version>3.0</version>
</dependency>
</dependencies>
</plugin>
打包到本地仓库
mvn install
命令行执行
mvn com.wurd:wu_m:0.1:test
pom引用
<plugins>
<plugin>
<groupId>com.wurd</groupId>
<artifactId>wu_m</artifactId>
<version>0.1</version>
</plugin>
</plugins>