上面的FixDirMojo实现了fixdir goal,其具体功能就是文中开始提到的将src的目录补完整(特别说一个,按照Maven工程的实际使用,这里并不完整,比如assembly,profile目录等都未创建)。
限于篇幅有关Annotation的具体使用可以参见:#Supported_Annotations
另外一个最好不过的方式就是通过Java Decompiler工具将现有个Maven Plugin反编译之后看看这些注解的具体使用。
4.编译,生成Plugin的描述文件,发布
hello-maven-plugin>mvn compiler:compile
hello-maven-plugin>mvn plugin:descriptor
hello-maven-plugin>mvn install
也可以直接执行:mvn install
通过plugin:descriptor将对Mojo进行处理,生成plugin.xml。关于描述下面是其中一部分摘取:
<plugin>
<name>hello-maven-plugin Maven Mojo</name>
<description></description>
<groupId>secondriver.maven.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0</version>
<goalPrefix>hello</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>fixdir</goal>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<implementation>secondriver.maven.plugin.hello.FixDir</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>true</threadSafe>
<parameters>
<parameter>
<name>baseDir</name>
<type>java.io.File</type>
<required>false</required>
<editable>false</editable>
<description></description>
</parameter>
<parameter>
<name>packageName</name>
<type>java.lang.String</type>
<required>true</required>
<editable>true</editable>
<description></description>
</parameter>
<parameter>
<name>project</name>
<type>org.apache.maven.project.MavenProject</type>
<required>false</required>
<editable>true</editable>
<description></description>
</parameter>
</parameters>
<configuration>
<baseDir implementation="java.io.File" default-value="${project.basedir}"/>
<packageName implementation="java.lang.String" default-value="${project.groupId}">${fixdir.packageName}</packageName>
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
</configuration>
</mojo>
</mojos>
</plugin>