Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

With the current Mojo descriptor extractor, it is possible to inherit Mojo annotations from parent classes, but not across projects. With this, it is e.g. not possible to subclass a "built-in" Maven mojo and inherit the annotations, or to refactor common Mojo code into a separate "Base Mojo" project, because the subclass lives in a different project. Since the annotation inheritance also only looks at parent classes, it is not possible to have annotated Mojo interfaces, e.g. for a Compiler which has different implementations.

To allow this, it should be possible to specify a list of prototypes for a Mojo. The descriptor extractor would then load the descriptors of these prototypes (from the plugin.xml) and merge them into a base descriptor for the Mojo, allowing it to inherit the annotations.

Example with MNG-2521 annotations:

Code Block
@Goal(goal = "clustered")
public interface ClusteredMojo {
    @Parameter
    private void setClusterController(String controller) {
        //...
    }
}

@Goal(goal = "compile", prototypes = {
	@Prototype(groupId="org.apache.maven.plugin", artifactId="maven-compiler-plugin", goal="compile"),
	@Prototype(goal="clustered")} )
public class MyCompilerMojo extends CompilerMojo implements ClusteredMojo {
	// ...
}

For convenience, the groupId and artifactId default to the current project's values, and the goal to the current annotation's goal.

For this to work, the descriptor extractors should also create descriptors for annotated interfaces and abstract classes. These should be written into the plugin.xml and filtered out by the PluginDiscoverer, so they cannot be accessed normally.