gpt4 book ai didi

java - 无法将 Maven 插件绑定(bind)到编译阶段

转载 作者:行者123 更新时间:2023-11-30 09:20:23 26 4
gpt4 key购买 nike

我一直在尝试使用注释编写一个 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 出现确认插件绑定(bind)到编译阶段:

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 会自动绑定(bind)到编译阶段,所以如果我输入

mvn clean compile

它会自动运行。我是否遗漏了一些明显的东西?

真正的源代码在这里:

https://github.com/teverett/jvmBASIC/tree/master/jvmbasicmojo

最佳答案

你似乎对 dependency in your pom for your mojo 有问题.您应该使用以下内容:

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>

代替

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>

此外,使用 maven-plugin-plugin 会更干净,如下所示:

    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<configuration>
<goalPrefix>jvmbasic</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-descriptor</id>
<goals>
<goal>helpmojo</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>

另一点是在 mojo 区域定义 maven-compiler-plugin 版本,因为您不为项目使用全局父 pom。

关于java - 无法将 Maven 插件绑定(bind)到编译阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com