Powered by:
SourceForge.net Built by Maven
Sponsored by:
AlphaCSP

Introduction

This is a Maven2 extension of maven-plugin-plugin that allows writing Annotated Plug-in Mojos using JDK 1.5+ annotations instead of doclet comments.

This has a couple of benefits over using JavaDoc-style annotations:

  • You will get compile-time checks for your plugin metadata.
  • You can use annotations on interface getter methods instead of field annotations, which allows for greater flexibility in your plugin object model.
  • Since JDK 1.5 annotations are supported in most IDEs, you will benefit from code-completion and syntactic checks.
Enjoy.

Prerequisites

  1. JDK 5.0 or later
  2. Maven 2.0.5 or later
  3. maven-plugin-plugin 2.2 or later

Settings

download zip repository

Use the download link to get from sourceforge the zip of a maven2 format repository containing Maven Anno Mojo artifacts.

If you are using Artifactory, the Web UI page "import/export" emables to import this zip directly into Artifactory.

jfrog repository

You can also configure a maven repository with the following URL: http://www.jfrog.org/artifactory/plugins-releases

to retrieve the latest version of maven anno mojo.

POM configuration

<project>
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.jfrog.maven.annomojo</groupId>
            <artifactId>maven-plugin-anno</artifactId>
            <version>1.3.1</version>
        </dependency>
        ...
    </dependencies>

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>2.3</version>
                <dependencies>
                    <dependency>
                        <groupId>org.jfrog.maven.annomojo</groupId>
                        <artifactId>maven-plugin-tools-anno</artifactId>
                        <version>1.3.1</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
</project>

Using Mojo Annotations

NOTE

This plugin relies on JDK 1.5 and uses the Annotation Processing Tool (APT). It is required to run Maven with JDK 1.5 or later (set your JAVA_HOME to point to the JDK not the JRE).

Class and Field Annotations

The Anno Mojo API project reports has the javadoc that can help.

Simple Example

/**
 * My mojo description
 */
@MojoGoal("doIt")
@MojoPhase("package")
@MojoExecute(phase = "package")
public class MyMojo {

    @MojoParameter
    private List<Artifact> artifacts;

    @MojoParameter(expression = "${project}", required = true, readonly = true,
            description = "The Maven Project")
    private MavenProject project;

    /**
     * The local repository
     */
    @MojoParameter(expression = "${localRepository}")
    private ArtifactRepository localRepository;

    ...
}

Element description is taken either from the element's JavaDoc comment or from a "description" attribute on appropriate annotations.

Getter Methods Annotations

You can also use field annotations on getter methods, either in interfaces or regular classes.

For example:

public interface MvnAnnoIfc {
    @MojoComponent(description =
        "project-helper instance, used to make addition of resources simpler.")
    MavenProjectHelper getProjectHelper();
}

Jade Plugins

A good start for Maven Anno Mojo, is to use Jade Plugins common jars. Jade Plugins has also many standard maven plugins converted to Java5 with Generics and Annotations.