每個mojo都必須使用@Goal標註來表明其目標名稱,否則maven將無法識別該目標。還有其他很多標註,列舉如下:
@goal <name>:唯一必須聲明的標註,當用戶命令行調用或在pom中配置插件是,需使用該目標名稱
@phase <phase>:默認將該目標綁定至default聲明週期的某個階段,這樣在配置使用插件目標時,就無需聲明phase,如maven-surefire-plugin的test目標帶有@phase tes標註
@requiresDependencyResolution <scope>:在運行mojo之前必須解析所有指定範圍的依賴,如maven-surefire-plugin的test目標帶有requiresDependencyResolution test標註,表示執行測試前,所有測試範圍的依賴必須得到解析
@requiresProject <true/false>:該目標是否必須在一個maven項目中運行(如測試插件用於測試其他項目),默認爲true。大部分插件目標需依賴一個項目才能運行,但是,maven-help-plugin的system目標例外,它用來顯示系統屬性和環境變量信息,無需實際項目。
@requiresOnline <true/false>:是否要求maven必須是在線狀態,默認值爲false
@requiresReport <true/false>:是否要求項目報告已經生成,默認爲false
@aggregator:當mojo在多模塊項目上運行時,該標註表示目標只會在頂層模塊運行。
@requiresDirectInvocation <true/false>:爲true時,該目標就只能通過命令行直接調用。默認爲false
@execute goal="<goal>":在運行該目標之前,讓maven運行另外一個目標。如果是本插件目標,則直接調用目標名稱,否則,使用“prefix:goal”
@execute phase="<phase>":在運行該目標前,讓maven先運行一個並行的生命週期,到指定的階段爲止。到phase執行完,才執行插件目標
@execute lifecycle="<lifecycle>" phase = "<phase>":在運行該目標前,讓maven先運行一個自定義的生命週期,到指定的階段爲止。
mojo參數
如可使用@parameter將mojo的某個字段標註爲可配置參數,即mojo參數。支持boolean,int,float,String,Date,File,Url,數組,Collection,map,Propertes
boolean(boolean和Boolean):
/**
*/
private boolean sampleBoolean:對應配置<sampleBoolean>true</sampleBoolean>
int(Integer,long.Long,short,Short,byte,Byte):
/**
*/
private int sampleInt:對應配置<sampleInt>8</sampleInt>
float(Float,Double,double):
/**
*/
private float sampleFloat:對應配置<sampleFloat>8.2</sampleFloat>
String(StringBuffer,char,Character):
/**
*/
private String sampleString:對應配置<sampleString>heoll</sampleString>
Date(yyyy-MM-dd HH:mm:ss.S a或yyyy-MM-dd HH:mm:ssa):
/**
*/
private Date sampleDate:對應配置<sampleDate>2010-06-09 3:14:55.1 PM或2010-06-09 3:14:55 PM</sampleDate>
File
/**
*/
private File sampleFile:對應配置<sampleFile>c:tem</sampleFile>
URL
/**
*/
private URL sampleUrl:對應配置<sampleUrl>http;//www.baidu.com</sampleUrl>
數組
/**
*/
private String[] includes:對應配置<includes><include>ee</include><include>dd</include></includes>
Collection(任何實現Collection接口的類)
/**
*/
private List includes:對應配置<includes><include>ee</include><include>dd</include></includes>
Map
/**
*/
private Map includes:對應配置<includes><key1>ee</key1><key2>dd</include></key2></includes>
Properties
/**
*/
private Properties includes:對應配置
<includes>
<property>
<name>ee</name>
<value>22</value>
</property>
<property>
<name>dd</name>
<value>11</value>
</property>
</includes>
@parameter額外屬性:
@parameter alias="<aliasName>":爲mojo參數使用別名
@parameter expression="${aSystemProperty}":使用系統屬性表達式對mojo參數進行賦值
@parameter defaultValue="aValue/${anExpression}":提供一個默認值
另外
@readonly:只讀屬性,不允許配置
@required:必需的屬性,未配置,會報錯