diff --git a/maven-site/src/site/xdoc/developers/mojo-api-specification.xml b/maven-site/src/site/xdoc/developers/mojo-api-specification.xml index ea4b958809..7a9c336567 100644 --- a/maven-site/src/site/xdoc/developers/mojo-api-specification.xml +++ b/maven-site/src/site/xdoc/developers/mojo-api-specification.xml @@ -91,13 +91,15 @@
- void setLog( org.apache.maven.monitor.logging.Log )
+ void setLog( org.apache.maven.monitor.logging.Log )
Inject a standard Maven logging mechanism to allow this Mojo to communicate events and feedback to the user.
void execute() throws org.apache.maven.plugin.MojoExecutionException
+
+ void execute() throws org.apache.maven.plugin.MojoExecutionException
+
Perform whatever build-process behavior this Mojo implements. This is the main trigger for the Mojo inside the Maven system, and allows the Mojo to communicate fatal errors by throwing an @@ -128,7 +130,7 @@
- public void setLog( org.apache.maven.monitor.logging.Log )
+ public void setLog( org.apache.maven.monitor.logging.Log )
[IMPLEMENTED] @@ -146,7 +148,7 @@
- void execute() throws org.apache.maven.plugin.MojoExecutionException
+ void execute() throws org.apache.maven.plugin.MojoExecutionException
[ABSTRACT] @@ -178,7 +180,7 @@
- void debug( java.lang.CharSequence, java.lang.Throwable )
+ void debug( java.lang.CharSequence, java.lang.Throwable )
Send a message (and accompanying exception) to the user in the debug error level. The error's stacktrace will be output @@ -196,7 +198,7 @@
- void info( java.lang.CharSequence, java.lang.Throwable )
+ void info( java.lang.CharSequence, java.lang.Throwable )
Send a message (and accompanying exception) to the user in the info error level. The error's stacktrace will be output @@ -214,7 +216,7 @@
- void warn( java.lang.CharSequence, java.lang.Throwable )
+ void warn( java.lang.CharSequence, java.lang.Throwable )
Send a message (and accompanying exception) to the user in the warn error level. The error's stacktrace will be output @@ -232,7 +234,7 @@
- void error( java.lang.CharSequence, java.lang.Throwable )
+ void error( java.lang.CharSequence, java.lang.Throwable )
Send a message (and accompanying exception) to the user in the error error level. The error's stacktrace will be output @@ -262,71 +264,127 @@ element name along with a javadoc annotation (if applicable) supporting that piece of the plugin descriptor. A couple of examples are: someElement - (@annotation parameterName="parameterValue") or + (@annotation parameterName="parameterValue") or someOtherElement (@annotation <rawAnnotationValue>).
The plugin descriptor must be provided in a jar resource with the
path: META-INF/maven/plugin.xml
, and it must contain the
following:
-
Descriptor Element | +Required? | +Notes | +
---|---|---|
mojos | +Yes | +Descriptors for each Mojo provided by the plugin, each inside a + mojo sub-element. Mojo descriptors are covered in detail + below. Obviously, a plugin without any declared mojos doesn't + make sense, so the mojos element is required, along with + at least one mojo sub-element. | +
dependencies | +Yes | +A set of dependencies which the plugin requires in order to
+ function. Each dependency is provided inside a dependency
+ sub-element. Dependency specifications are covered below. Since
+ all plugins must have a dependency on
+ maven-plugin-api , this element is effectively
+ required. Using the plugin toolset, these dependencies can be
+ extracted from the POM's dependencies. |
+
Each Mojo specified inside a plugin descriptor must provide the - following:
+ following (annotations specified here are at the class level):-
Descriptor Element | +Annotation | +Required? | +Notes | +
---|---|---|---|
goal | +@goal <goalName> | +Yes | +The name for the Mojo that users will reference from the + command line to execute the Mojo directly, or inside a POM in + order to provide Mojo-specific configuration. | +
implementation | +none (detected) | +Yes | +The Mojo's fully-qualified class name (or script path in + the case of non-java mojos). | +
language | +none (detected) | +No. Default: java |
+ The implementation language for this Mojo (marmalade, java, + beanshell, etc.). | +
configurator | +none (detected) | +No | +The configurator type to use when injecting parameter values + into this Mojo. NOTE: This will only be used in very special + cases, using a highly controlled vocabulary of possible values. + (Elements like this are why it's a good idea to use the + descriptor tools.) | +
phase | +@phase <phaseName> | +No | +Binds this Mojo to a particular phase of the standard build + lifecycle, if specified. NOTE: This is only required if this + Mojo is to participate in the standard build process. | +
executePhase | +@executePhase <phaseName> | +No | +When this Mojo's goal is invoked directly from the command + line, executePhase specifies the last phase in the + standard build lifecycle to execute before this Mojo + executes. | +
requiresDependencyResolution | +@requiresDependencyResolution <requiredScope> | +No | +Flags this Mojo as requiring the dependencies in the specified + scope (or an implied scope) to be resolved before it can execute. + NOTE: Currently supports compile, + runtime, and test scopes. | +
description | +none (detected) | +No | +The description of this Mojo's functionality. Using the + toolset, this will be the class-level javadoc description + provided. NOTE: While this is not a required part of the mojo + specification, it SHOULD be provided to enable future + tool support for browsing, etc. and for clarity. | +
parameters | +N/A | +No | +Specifications for the parameters which this Mojo uses will be + provided in parameter sub-elements in this section. + NOTE: Parameters are discussed in more detail below. | +
Each Mojo specifies the parameters that it expects to be able to work with. These parameters are the Mojo's link to the outside world, and @@ -344,63 +402,104 @@
Each parameter for a Mojo must be specified in the plugin descriptor as follows:
-
Descriptor Element | +Annotation | +Required? | +Notes | +
---|---|---|---|
name | +none (detected) | +Yes | +The name of the parameter, to be used in configuring this + parameter from the Mojo's declared defaults (discussed below) or + from the POM. Using the toolset, this is detected as the + java field name. | +
alias | +@parameter alias="myAlias" | +No | +Specifies an alias which can be used to configure this + parameter from the POM. This is primarily useful to improve + user-friendliness, where Mojo field names are not intuitive to + the user or are otherwise not conducive to configuration via + the POM. | +
type | +none (detected) | +Yes | +The java type for this parameter. This is used to validate the + result of any expressions used to calculate the value which + should be injected into the Mojo for this parameter. Using the + toolset, this is detected as the class of the java field + corresponding to this parameter. | +
required | +@required | +No | +Whether this parameter is required for the Mojo to function. + This is used to validate the configuration for a Mojo before it + is injected, and before the Mojo is executed from some + half-state. NOTE: Specification of this annotation flags + the parameter as required; there is no true/false value. | +
editable | +@readonly | +No | +Specifies that this parameter cannot be configured directly by + the user (as in the case of POM-specified configuration). This is + useful when you want to force the user to use common POM elements + rather than plugin configurations, as in the case where you want + to use the artifact's final name as a parameter. In this case, + you want the user to modify + <build><finalName/></build> rather than + specifying a value for finalName directly in the plugin + configuration section. It is also useful to ensure that - for + example - a List-typed parameter which expects items of type + Artifact doesn't get a List full of Strings. NOTE: + Specification of this annotation flags the parameter as + non-editable; there is no true/false value. | +
description | +none (detected) | +No | +The description of this parameter's use inside the Mojo. + Using the toolset, this is detected as the javadoc description + for the field. NOTE: While this is not a required part of the + parameter specification, it SHOULD be provided to enable future + tool support for browsing, etc. and for clarity. | +
expression | +@parameter expression="${someExpression}" | +No | +Specifies the expression used to calculate the value to be + injected into this parameter of the Mojo at buildtime. This is + commonly used to refer to specific elements in the POM, such as + ${project.build.resources}, which refers to the List of resources + meant to accompany the classes in the resulting jar file. + NOTE: If not specified, an expression of ${<name>} is + assumed, which can only be satisfied from POM configuration or + System properties. The use of '${' and '}' is required to delimit + actual expressions which may be evaluated. | +
deprecated | +@deprecated | +No | +Marks a parameter as deprecated. The rules on deprecation are + the same as normal java with language elements. This will trigger + a warning when a user tries to configure a parameter marked as + deprecated. | +
The final component of a plugin descriptor is the dependencies. This
enables the plugin to function independently of it's POM (or at least
@@ -413,14 +512,17 @@
By now, we've mentioned the plugin tools several times without telling
- you what they are or how to use them. instead of writing (and
- maintaining) this metadata file by hand, Maven 2.0 ships with some
- tools to aid developers in this task. In fact, the only thing a plugin
- developer needs to do is declare his project to be a plugin from within
- the POM. Once this is done, Maven will call the appropriate descriptor
+ you what they are or how to use them. Instead of manually writing (and
+ maintaining) the metadata detailed above, Maven 2.0 ships with some
+ tools to aid in this task. In fact, the only thing a plugin developer
+ needs to do is declare his project to be a plugin from within the POM.
+ Once this is done, Maven will call the appropriate descriptor
generators, etc. to produce an artifact that is ready for use within
- Maven builds. The section below describes the changes to the POM
- which are necessary to create plugin artifacts.
From the POM, Maven plugin projects look quite similar to any other @@ -428,30 +530,52 @@ for script-based plugins. The following details the POM elements which are necessary to build a Maven plugin artifact.
-
<packaging>maven-plugin</packaging>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
.
- This directory is included in the list of resources which accompany
- any compiled code in the resulting artifact. It is specified
- separately from the resources in the build section to denote its
- special status as an alternate source directory for scripts.POM Element | +Required for Java Mojos? | +Sample Declaration | +Notes | +
---|---|---|---|
packaging | +Yes | +<packaging>maven-plugin</packaging> |
+ The POM must declare a packaging element which describes this + project as a Maven plugin project. | +
scriptSourceDirectory | +No | +<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> |
+ In the case of script-based Mojos (which are not covered in + detail within this document), the POM must include an additional + element to distinguish script sources from (optional) java + supporting classes. This element is the scriptSourceDirectory, + inside the build section. This directory is included in the list + of resources which accompany any compiled code in the resulting + artifact. It is specified separately from the resources in the + build section to denote its special status as an alternate source + directory for scripts. | +
After making the changes above, the developer can simply call m2
- install
to install the plugin to the local repository. (Any of
- the other standard lifecycle targets like package, deploy, etc. are
- also available in like fashion.)
After making the changes above, the developer can simply call
+ m2 install
to install the plugin to
+ the local repository. (Any of the other standard lifecycle targets like
+ package, deploy, etc. are also available in like fashion.)
This section simply gives a listing of pointers for more + information.
++
+