diff --git a/maven-site/src/site/apt/guides/mini/guide-configuring-plugins.apt b/maven-site/src/site/apt/guides/mini/guide-configuring-plugins.apt index 85bf4027c4..17f3947f73 100644 --- a/maven-site/src/site/apt/guides/mini/guide-configuring-plugins.apt +++ b/maven-site/src/site/apt/guides/mini/guide-configuring-plugins.apt @@ -8,8 +8,33 @@ Guide to Configuring Plug-ins + In Maven plug-ins are configured by specifying a <<>> element where the child elements of the + <<>> element are mapped to fields, or setters, inside your Mojo (remember that a plug-in consists of + one or more Mojos where a Mojo maps to a goal). Say, for example, we had a Mojo that performed a query against + a particular URL, with a specified timeout and list of options. The Mojo might look like the following: ++----+ +public class MyQueryMojo + extends AbstractMojo +{ + private String url; + + private int timeout; + + private String[] options; + + public void execute() + throws MojoExecutionException + { + ... + } +} + ++----+ + + To configure the Mojo from your POM with the desired URL, timeout and options you might have something like + the following: +----+ @@ -20,6 +45,8 @@ Guide to Configuring Plug-ins maven-assembly-plugin + http://www.foobar.com/query + 10 @@ -32,4 +59,54 @@ Guide to Configuring Plug-ins ... ++----+ + + As you can see the elements in the configuration match the names of the fields in the Mojo. The configuration + mechanism Maven employs is very similar to the way {{{http://xstream.codehaus.org}XStream}} works where elements + in XML are mapped to objects. So from the example above you can see that the mapping is pretty straight forward the + <<>> element maps to the <<>> field, the <<>> element maps to the <<>> field and the + <<>> element maps to the <<>> field. The mapping mechanism can deal with arrays by inspecting + the type of the field and determining if a suitable mapping is possible. + +* Mapping to collections + +** Mapping lists + +** Mapping maps + +** Mapping properties + +* Mapping complex objects + +* Using setters + + You are not restricted to using private field mapping which is good if you are trying to make you Mojos resuable + outside the context of Maven. Using the example above we could name our private fields using the underscore + convention and provide setters that the configuration mapping mechanism can use. So our Mojo would look + like the following: + ++----+ + +public class MyQueryMojo + extends AbstractMojo +{ + private String _url; + + private int _timeout; + + private String[] _options; + + public void setUrl( String url ){ _url = url; } + + public void setTimeout( int timeout ){ _timeout = timeout; } + + public void setOptions( String[] options ){ _options = options; } + + public void execute() + throws MojoExecutionException + { + ... + } +} + +----+