• No labels

1 Comment

  1. Unknown User (eredmond)

    Using Java 5 Annotations

    Currently only available in mvn 2.1.x

    Since Java 5 annotations are not built in to Maven core (yet) they require a bit of wrangling to use. Your plugin's pom must contain the following:

      <dependencies>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-plugin-tools-java5</artifactId>
          <version>2.2-SNAPSHOT</version>
        </dependency>
        ...
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>2.4-SNAPSHOT</version>
            <dependencies>
              <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-plugin-tools-java5</artifactId>
                <version>2.2-SNAPSHOT</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <goals>
                  <goal>post-compile-descriptor</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.5</source>
              <target>1.5</target>
            </configuration>
          </plugin>
          ...
        </plugins>
      </build>

    Firstly, you must add the annotation dependency to your plugin's dependency list.

        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-plugin-tools-java5</artifactId>
          <version>2.2-SNAPSHOT</version>
        </dependency>

     This allows your project mojos access to the 4 annotation classes:

    • org.apache.maven.tools.plugin.Goal 
    • org.apache.maven.tools.plugin.Execute
    • org.apache.maven.tools.plugin.Parameter
    • org.apache.maven.tools.plugin.Component

    The first two are Type (class-level) annotation, the last two are Field annotations.

    There is also an enum org.apache.maven.tools.plugin.lifecycle.Phase - which contains values corresponding to the default phases (VALIDATE, COMPILE, TEST, DEPLOY...), clean (PRE_CLEAN, CLEAN...) and site (SITE, SITE_DEPLOY...). The Goal "defaultPhase" field accepts an enum Phase value only as well as the Execute "phase" field accepts an enum Phase ("customPhase" field can accept a string).

    Currently you must add the "maven-plugin-tools-java5" artifact to the maven-plugin-plugin dependency, since it is not a dependency by default. Moreover, you must add "post-compile-descriptor" goal execution (binds to "process-classes"). The compiler must also be set to jdk 1.5 or greater, or your mojo compilation will fail.

    Note: The existing maven-plugin-plugin will fail if no mojos are found during the "descriptor" goal execution (which is run as part of a "maven-project" packaging type. Since you cannot skip this goal - your plugin either must contain a mojo using plain-old-fashioned javadoc annotations - or package your project as a "jar" and manually add the other plugin-plugin goal executions - or add a javadoc to one goal with a /** @goal "name" */ class comment. None are good long-term solutions, so this must be fixed.