Annotation Interface InjectMojo


@Target({METHOD,PARAMETER}) @Retention(RUNTIME) @Inherited public @interface InjectMojo
Annotation used in Maven plugin tests to inject and configure a Mojo instance. This annotation can be applied to either test methods or parameters to specify which Mojo should be instantiated and how it should be configured.

The annotation requires a goal attribute to specify which Mojo goal should be instantiated. Optionally, a custom pom file can be specified to provide specific configuration for the test.

Example usage on a test method:

 
 @Test
 @InjectMojo(goal = "compile")
 void testCompileMojo(CompileMojo mojo) {
     mojo.execute();
     // verify compilation results
 }
 
 

Example usage with a custom POM:

 
 @Test
 @InjectMojo(
     goal = "compile",
     pom = "src/test/resources/test-pom.xml"
 )
 void testCompileMojoWithCustomConfig(CompileMojo mojo) {
     mojo.execute();
     // verify compilation results
 }
 
 

The annotation can be used in conjunction with MojoParameter to provide specific parameter values for the Mojo:

 
 @Test
 @InjectMojo(goal = "compile")
 @MojoParameter(name = "source", value = "1.8")
 @MojoParameter(name = "target", value = "1.8")
 void testCompileMojoWithParameters(CompileMojo mojo) {
     mojo.execute();
     // verify compilation results
 }
 
 
Since:
4.0.0
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Specifies the goal of the Mojo to instantiate.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies an optional POM file to use for Mojo configuration.
  • Element Details

    • goal

      String goal
      Specifies the goal of the Mojo to instantiate. This is a required attribute that maps to the Mojo's @Mojo(name = "...") annotation value.
      Returns:
      the goal name of the Mojo to test
    • pom

      String pom
      Specifies an optional POM file to use for Mojo configuration. The path is relative to the test class location.

      If not specified, the default project configuration will be used.

      Returns:
      the path to a custom POM file, or an empty string to use defaults
      Default:
      ""