我正在按照 教程创建一个 maven 插件,不能运行 mvn install 而不出错。信息抱怨说我没有所需的魔力描述符,而注释应该为我生成它们。我正在运行 Maven3.0.5,并使用 intellij 作为我的主页。这是我的主要课程:
@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