gpt4 book ai didi

java - 基本 maven 插件项目不工作,Mojo 插件描述符不生成

转载 作者:IT老高 更新时间:2023-10-28 13:53:05 25 4
gpt4 key购买 nike

我正在关注 tutorial用于创建 maven 插件并且无法运行 mvn install 而不会出现错误。当注释应该为我生成它们时,该信息提示我没有所需的 mojo 描述符。我正在运行 maven 3.0.5 并使用 intellij 作为我的 ide。这是我的主要类(class):

@Mojo(name = "modify-connector")
public class ComplianceMojo extends AbstractMojo {

@Parameter
private String artifactId;

@Parameter
private String version;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File jar = new File(getPluginContext().get("project.build.directory") + "/"
+ getPluginContext().get("project.build.finalname") + "/" + artifactId + "-" + version);
if(jar.exists()){
getLog().info("The file exists! " + jar.getAbsolutePath());
} else {
getLog().info("The file does not exist: " + jar.getAbsolutePath());
}
}
}

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>mysql-jdbc-compliance-maven-plugin</groupId>
<artifactId>mysql-jdbc-compliance-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<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.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>

注意:我不得不单独添加注解依赖,因为主插件 api 不包含这些类。当我在我的项目上运行 mvn install 时,输出如下:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.867s
[INFO] Finished at: Wed Sep 25 17:45:55 EST 2013
[INFO] Final Memory: 8M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:2.9:descriptor (default-descriptor) on project mysql-jdbc-compliance-maven-plugin: Error extracting plugin descriptor: 'No mojo definitions were found for plugin: mysql-jdbc-compliance-maven-plugin:mysql-jdbc-compliance-maven-plugin.' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

最佳答案

这可能与 Maven 中 Unresolved 问题有关:https://issues.apache.org/jira/browse/MNG-5346

对于我的插件项目,我可以通过添加 maven-plugin-plugin 的显式执行来解决:

<build>
<plugins>
<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>
</plugins>
</build>

但请参阅 JIRA 问题中的评论以获得更详细的解决方案!

关于java - 基本 maven 插件项目不工作,Mojo 插件描述符不生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18999401/

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