maven之无法在自定义 Maven 插件中找到目标

lyhabc 阅读:32 2024-10-01 17:34:08 评论:0

我正在尝试开发自定义 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(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 文件中的片段:

<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> 

请您参考如下方法:

如果您使用旧式 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
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号