我一直在尝试使用注释编写一个 Maven 插件。我的插件声明如下所示:
@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresProject = true, threadSafe = false)
public class CompileMojo extends AbstractMojo
我在编译插件的 pom 文件中有这个:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 --> <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
maven 似乎确认插件已绑定到编译阶段:
mvn help:describe -DartifactId=jvmbasic-maven-plugin -DgroupId=com.khubla.jvmbasic -Dgoal=compile -Ddetail
[INFO] Mojo: 'jvmbasic:compile'
jvmbasic:compile
Description: jvmBASIC compiler
Implementation: com.khubla.jvmbasic.jvmbasicmojo.CompileMojo
Language: java
Bound to phase: compile
Available parameters:
sourceDir
where to find the sources
targetDir
target dir
verbose
verbose
当我明确调用 mojo 时,它会起作用:
mvn jvmbasic:compile
如果我在 pom 文件中使用执行部分,它也可以工作。但是,我曾预计 mojo 会自动绑定到编译阶段,所以如果我输入
mvn clean compile
它会自动运行。我错过了一些明显的东西吗?
实际的源代码在这里:
https://github.com/teverett/jvmBASIC/tree/master/jvmbasicmojo