我有自己的Mojo类(class)。

 @Mojo(name="mojo", threadSafe=true)
 public class MyMojo extends AbstractMojo
 {
     @Component
     private MavenProject project;

     public void execute() throws MojoExecutionException, MojoFailureException
     {
        getLog().info("Execute");
     }
  }

之后,我将其安装在本地存储库中。
 [INFO] Applying mojo extractor for language: java-annotations
 [INFO] Mojo extractor for language: java-annotations found 0 mojo descriptors.
 [INFO] Applying mojo extractor for language: java
 [INFO] Mojo extractor for language: java found 0 mojo descriptors.
 [INFO] Applying mojo extractor for language: bsh
 [INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
 ....
 [INFO] BUILD SUCCESS

但是,当尝试调用“mojo”目标时,我得到了错误
   [ERROR] Could not find goal 'mojo' in plugin my.plugins:my-plugin:1.0-SNAPSHOT among available goals -> [Help 1]

what is the problem?

这是maven-plugin-plugin配置。
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.2</version>
    <configuration>
        <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
     </configuration>
 </plugin>

具有javadoc注释的旧机制效果很好,但我想使用Java注释。
<dependency>
    <groupId>org.apache.maven.plugin-tools</groupId>
    <artifactId>maven-plugin-annotations</artifactId>
    <version>3.2</version>
</dependency>


 [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ bla-mvn-plugin

为什么启用default-descriptor而不是mojo-descriptor?

最佳答案

将此部分添加到插件的POM中:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
                <executions>
                    <execution>
                        <id>mojo-descriptor</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

PS。有关构建带有注释的MOJO的完整工作示例,请参见maven-compiler-plugin:3.0源。

10-05 23:09