【问题标题】:Could not find goal in custom maven plugin在自定义 maven 插件中找不到目标
【发布时间】:2013-03-13 15:13:05
【问题描述】:

我正在尝试开发一个自定义 Maven 插件,我正在按照此处描述的官方 maven 文档中的教程进行操作:

http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

但是,当我尝试使用来自不同项目的插件时,我得到以下信息:

Could not find goal 'generateProtoClasses' in plugin com.myComapny.maven.plugin:myCompany-protobuf-plugin:1.0 among available goals -> [Help 1]

这是我的 MOJO:

@Mojo(name = "generateProtoClasses", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public class CompileProtoClasses extends AbstractMojo {


    @Parameter(defaultValue = "mokmok")
    private String inputPath;

    public void execute() throws MojoExecutionException {
        getLog().info("@@@@@@@@@@@@@@@@@@@@@@@");
        getLog().info(inputPath);
    }

}

这是使用插件的项目的pom.xml文件上的sn-p:

<plugin>
        <groupId>com.myCompany.maven.plugin</groupId>
        <artifactId>legolas-protobuf-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <inputPath>yoyo</inputPath>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>generateProtoClasses</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

插件项目的Pom:

<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>com.myCompany.maven.plugin</groupId>
    <artifactId>myCompany-protobuf-plugin</artifactId>
    <version>1.0</version>
    <packaging>maven-plugin</packaging>

    <name>protobuf-plugin Maven Plugin</name>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>3.0.5</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-tools-api</artifactId>
            <version>3.2</version>
        </dependency>


        <!-- dependencies to annotations -->
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.2</version>
            <!-- annotations are not needed for plugin execution so you can remove 
                this dependency for execution with using provided scope -->
            <scope>provided</scope>
        </dependency>
        <!-- generated help mojo has a dependency to plexus-utils -->
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>3.0.1</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

  • 你在使用 maven-plugin-annotations 吗?可以显示插件的pom吗?
  • 添加了插件的pom
  • 将您的班级名称更改为 WhatEverMojo 并重新测试。检查你在课堂上的大小写混合是否有问题。

标签: maven maven-plugin


【解决方案1】:

如果您使用旧式 xdoclet 注释,它是否有效?

/**
 * @goal generateProtoClasses
 * @phase generate-resources
 */
public class CompileProtoClasses extends AbstractMojo {

    /**
     * @parameter default-value="mokmok"
     */
    private String inputPath;

    public void execute() throws MojoExecutionException {
        getLog().info("@@@@@@@@@@@@@@@@@@@@@@@");
        getLog().info(inputPath);
    }
}

【讨论】:

  • 同样,我被 Maven 3.0.5 困住,无法在我们的环境中轻松更改它,删除 @Mojo 注释并用 xdoclet 样式注释替换它也对我有用。跨度>
【解决方案2】:

将以下内容添加到您的 build->maven-plugin-plugin

<execution>
  <id>mojo-descriptor</id>
  <goals>
    <goal>descriptor</goal>
  </goals>
</execution>

【讨论】:

  • 我认为这是正确的问题。当使用注释来定义你的 mojo(不是 doclet)时,你需要这个执行来在使用 mojo 时启用 mojo 识别。
【解决方案3】:

我在使用 maven 3.0.5(Netbeans 内置)时遇到此错误 获取最新的 maven 版本并再次构建 maven-plugin。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2021-06-27
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 2018-04-13
    • 2021-09-12
    相关资源
    最近更新 更多