Annotation Interface MojoParameter
@Target({METHOD,PARAMETER})
@Retention(RUNTIME)
@Inherited
@Repeatable(MojoParameters.class)
public @interface MojoParameter
Specifies a parameter value for a Mojo in a Maven plugin test.
This annotation can be used to configure individual Mojo parameters
without requiring a full POM file.
The annotation is repeatable, allowing multiple parameters to be set
on a single test method or parameter. For multiple parameters, you can
either use multiple @MojoParameter annotations or a single
MojoParameters annotation.
Example usage with a single parameter:
@Test
@InjectMojo(goal = "compile")
@MojoParameter(name = "source", value = "1.8")
void testCompilation(CompileMojo mojo) {
mojo.execute();
}
Example usage with multiple parameters:
@Test
@InjectMojo(goal = "compile")
@MojoParameter(name = "source", value = "1.8")
@MojoParameter(name = "target", value = "1.8")
@MojoParameter(name = "debug", value = "true")
void testCompilation(CompileMojo mojo) {
mojo.execute();
}
- Since:
- 4.0.0
- See Also:
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional Elements
-
Element Details
-
name
String nameThe name of the Mojo parameter to set. This should match the name of a parameter in the Mojo class, as specified by its@Parameterannotation or field name.- Returns:
- the parameter name
-
value
String valueThe value to set for the parameter. The value can include Maven property expressions (e.g., "${project.version}").- Returns:
- the parameter value
-
xml
boolean xmlWhether to parse the value as XML. Whentrue(default), the value is parsed as XML content within the parameter element. Whenfalse, the value is treated as plain text (useful for comma-separated lists).Example with XML parsing enabled (default):
@MojoParameter(name = "items", value = "<item>one</item><item>two</item>")Example with XML parsing disabled:
@MojoParameter(name = "items", value = "one,two,three", xml = false)- Returns:
trueto parse as XML,falseto treat as plain text- Since:
- 4.0.0
- Default:
true
-