前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >maven/plugin开发:插件版本不匹配导致的报错:Method: ‘name’ not found in class in ParameterAnnotationContent

maven/plugin开发:插件版本不匹配导致的报错:Method: ‘name’ not found in class in ParameterAnnotationContent

作者头像
10km
发布2018-01-03 12:08:59
1.9K0
发布2018-01-03 12:08:59
举报
文章被收录于专栏:10km的专栏10km的专栏

问题描述

今天在写一个maven插件的时候报了错,意思就是插件类参数注释@Parameter中没有name这个方法(org.apache.maven.plugins.annotations.Parameter):

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2: descriptor (default-descriptor) on project swift2thrift-maven-plugin: Error extr acting plugin descriptor: ‘Method: ‘name’ not found in class: ‘class org.apache. maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent” -> [Help 1]

我在代码中的确使用了name。下面是我的代码片段

代码语言:javascript
复制
public class Swift2ThriftMojo extends AbstractMojo {
    private static final String SPLIT_REGEX = "\\s;,";
    /**
     * <Swift-class-name...>
     */
    @Parameter(name = "classNames",required=true)
    private List<String>  swiftClasseNames;
    //.....
}

原因分析

这怎么可能?! 如果annotation中没有定义name,我这代码编译都通不过呀。所以一定不是代码的问题。 仔细看看报错位置的错误信息(如下截图),发现maven在解析<packaging>maven-plugin</packaging>时使用的maven-plugin-plugin版本是3.2

这里写图片描述
这里写图片描述

而我用的maven-plugin-annotations版本是3.5

代码语言:javascript
复制
<properties>
    <dep.maven-api.version>3.5.0</dep.maven-api.version>
</properties>
<!-- maven -->
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-plugin-api</artifactId>
    <version>${dep.maven-api.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-model</artifactId>
    <version>${dep.maven-api.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-artifact</artifactId>
    <version>${dep.maven-api.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.maven.plugin-tools</groupId>
    <artifactId>maven-plugin-annotations</artifactId>
    <version>3.5</version>
</dependency>

到这里问题就清楚了: maven默认使用的maven-plugin-plugin插件版本过低,无法识别高版本annotation新增加的name方法。

解决方案

方案1

去掉代码中的name定义,把上面的maven插件开发依赖的相关库版本降到3.2.5/3.2。

方案2

指定使用maven-plugin-plugin版本为与maven插件开发依赖的相关库版本匹配的版本,比如3.5 在pom.xml加入如下代码

代码语言:javascript
复制
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-plugin-plugin</artifactId>
                    <version>3.5</version>
                </plugin>
            </plugins>
        </pluginManagement>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年12月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题描述
  • 原因分析
  • 解决方案
    • 方案1
      • 方案2
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档