Wednesday, 9 May 2012

Java5 annotations support for Maven plugins

So finally or at least (depends on your POV :-)), I have pushed some code to support Java5 annotations support for Maven plugins.
The "specs" are here
The code is available in the branch
Snapshot are deployed to: .
You can have a look at it tests to see some samples:
Basically you need to setup your pom as it:

      <name>Apache Snapshot Repository</name>
      <name>Apache Snapshot Repository</name>

Annotations to use are:
@Mojo( name = "foo", 
       defaultPhase = LifecyclePhase.COMPILE, 
       threadSafe = true )
@Execute( goal = "compiler", 
          lifecycle = "my-lifecycle", 
          phase = LifecyclePhase.PACKAGE )

public class FooMojo extends AbstractMojo
     * the cool bar to go
     * @since 1.0
    @Parameter( expression = "${thebar}", 
                required = true, 
                defaultValue = "coolbar" )
    protected String bar;

     * beer for non french folks
     * @deprecated wine is better
    @Parameter( expression = "${thebeer}", 
                defaultValue = "coolbeer" )
    protected String beer;

     * Plexus compiler manager.
    protected CompilerManager compilerManager;

    @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", 
                roleHint = "maven" )
    protected ArtifactMetadataSource artifactMetadataSource;

    public void execute()
        throws MojoExecutionException, MojoFailureException
        // nothing
Note: the help generation doesn't work yet !!
A new feature is your parent annotated classes can come from reactor project and from your project dependencies.
And don't complain yet too much in case of issues, it's a work in progress :-)
12 May 2012 UPDATE: Help generation done and code merged in trunk YEAHH :-)
25 May 2012 UPDATE: Few annotations has changed have a look at documentation page:
31 May 2012 UPDATE: release 3.0 deployed and now available.
Have Fun!

No comments: