为什么Maven找不到我的自定义Mojo?
我有自己的Mojo课程。
@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配置。
org.apache.maven.plugins maven-plugin-plugin 3.2 true
使用javadoc注释的旧机制运行良好,但我想使用java注释。
org.apache.maven.plugin-tools maven-plugin-annotations 3.2 [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ bla-mvn-plugin
为什么启用default-descriptor而不是mojo-descriptor?
将此部分添加到插件的POM中:
org.apache.maven.plugins maven-plugin-plugin 3.2 true mojo-descriptor process-classes descriptor
PS。 有关使用注释构建MOJO的完整工作示例,请参阅maven-compiler-plugin:3.0源代码
编辑(解决Mojo注释的使用):
我尝试使用注释构建插件并遇到同样的问题。 我通过将插件绑定到默认生命周期阶段来解决它,如下面@Mojo
注释中所示:
魔
@Mojo(name = "hello", defaultPhase = LifecyclePhase.INSTALL) public class MyMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Hello"); } }
Mojo POM
4.0.0 testware.mojotest mojotest 0.0.1-SNAPSHOT mojotest maven-plugin org.apache.maven maven-plugin-api 2.0 org.apache.maven.plugin-tools maven-plugin-annotations 3.2 org.apache.maven.plugins maven-plugin-plugin 3.2 true
项目的POM调用Mojo
4.0.0 testware.mojotest mojotest-runner 0.0.1-SNAPSHOT mojotest-runner testware.mojotest mojotest 0.0.1-SNAPSHOT compile hello