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
    Modifier and Type
    Required Element
    Description
    The name of the Mojo parameter to set.
    The value to set for the parameter.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether to parse the value as XML.
  • Element Details

    • name

      String name
      The name of the Mojo parameter to set. This should match the name of a parameter in the Mojo class, as specified by its @Parameter annotation or field name.
      Returns:
      the parameter name
    • value

      String value
      The value to set for the parameter. The value can include Maven property expressions (e.g., "${project.version}").
      Returns:
      the parameter value
    • xml

      boolean xml
      Whether to parse the value as XML. When true (default), the value is parsed as XML content within the parameter element. When false, 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:
      true to parse as XML, false to treat as plain text
      Since:
      4.0.0
      Default:
      true