Maven自定义插件描述符

时间:2013-04-11 09:04:46

标签: java maven maven-plugin

我正在尝试创建一个Maven插件,但是如果我使用@Mojo注释我已经使用maven plugin-plugin创建一个mojo描述符当我使用没有新的maven插件注释的java doc时,描述符会自动生成(或者maven不想要它)....

1案例:

@Mojo( name = "touch", requiresProject=false, defaultPhase = LifecyclePhase.INSTALL)
public class MyMojo
    extends AbstractMojo
{
     ....
}

POM:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>sample.plugin</groupId>
  <artifactId>hello-maven-pluginbis</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>maven-plugin</packaging>
  <name>first-maven-plugin Maven Mojo</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
     <groupId>org.apache.maven</groupId>
     <artifactId>maven-plugin-api</artifactId>
     <version>2.0</version>
   </dependency>
   <dependency>
     <groupId>org.apache.maven.plugin-tools</groupId>
     <artifactId>maven-plugin-annotations</artifactId>
     <version>3.1</version>
     <type>jar</type>
     <scope>compile</scope>
   </dependency>
 </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.2</version>

        </plugin>
    </plugins>
  </build>
 </project>

Maven不起作用

2案例:

/**
* Echos an object string to the output screen.
* @goal echo
* @requiresProject false
*/
public class EchoMojo extends AbstractMojo
{
   ....
}

POM:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.plugins</groupId>
<artifactId>first-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>first-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
  <dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-plugin-api</artifactId>
    <version>2.0</version>
  </dependency>
</dependencies> 

怎么可能?

1 个答案:

答案 0 :(得分:0)

您可能需要指定maven-plugin-plugin的目标来生成描述符吗?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.2</version>
            <executions>
                <execution>
                    <id>mojo-descriptor</id>
                    <goals>
                        <goal>descriptor</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>