Child pages
  • Maven Anno Mojo
Skip to end of metadata
Go to start of metadata

Introduction

This is a Maven 2 and 3 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 substantial benefits over using JavaDoc-style annotations:

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

Enjoy!

Prerequisites

  • JDK 5.0 or later
  • Maven 2.2.0 or later, Maven 3.0-beta-1 or later
  • maven-plugin-plugin 2.6 or later

Configuration

To use the plugin add Artifactory plugins repository and the plugin configuration to your pom.xml.

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

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>2.6</version>
                <dependencies>
                    <dependency>
                        <groupId>org.jfrog.maven.annomojo</groupId>
                        <artifactId>maven-plugin-tools-anno</artifactId>
                        <version>1.4.1</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>
            ...
        </plugins>
    </build>
    <profile>
        <id>jfrog-plugins</id>
        <pluginRepositories>
            <pluginRepository>
                <id>jfrog-plugins</id>
                <name>jfrog-plugins-dist</name>
                <url>http://repo.jfrog.org/artifactory/plugins-releases</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</project>

Use -Pjfrog-plugins on the first execution to download the plugin.

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).

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();
}

Links