Annotation Type InjectMojo


@Retention(RUNTIME) @Inherited @Target(METHOD) 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:
3.4.0
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
     
  • Element Details