基本的 Maven 插件项目不工作,Mojo 插件描述符不生成

新手上路,请多包涵

我正在按照创建 Maven 插件的 教程 进行操作,并且无法在不出现错误的情况下运行 mvn install。当注释应该为我生成时,信息抱怨我没有所需的 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());
        }
    }
}

这是我的 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

原文由 coderatchet 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 966
2 个回答

阅读 Gyro 发布的 Jira Issue 后,我将以下几行添加到我的 pom 中,一切都编译得很好。

 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <goalPrefix>mysql-jdbc-compliance</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>
    </plugins>
</build>

原文由 coderatchet 发布,翻译遵循 CC BY-SA 3.0 许可协议

也许这与 Maven 中未解决的问题有关: 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 问题中的评论以获得更详细的解决方案!

原文由 Gyro Gearless 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题