基本 maven 插件项目不起作用,Mojo 插件描述符不生成
2022-08-31 13:26:37
我正在按照创建maven插件的教程进行操作,并且无法在不出错的情况下运行mvn安装。该信息抱怨说,当注释应该为我生成它们时,我没有所需的mojo描述符。我正在运行maven 3.0.5并使用intellij作为我的ide。这是我的主要类:
@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());
}
}
}
这是我的绒球.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