You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义pig-maven-plugin使用时出现描述符groupId等信息错误求助

解决Pig-Maven-Plugin插件描述符错误的问题

这个错误的核心原因很明确:你的pig-maven-plugin-2.0.0.jar里包含了maven-resources-plugin的插件描述符(META-INF/maven/plugin.xml),而不是你自己插件的描述符。当Maven加载插件时,它读取到的是错误的plugin.xml,所以把你的插件识别成了org.apache.maven.plugins:maven-resources-plugin:3.0.2。

为什么会出现这个问题?

从你的POM配置来看,主要有两个诱因:

  1. 你直接依赖了maven-resources-plugin作为compile级别的依赖,这会把它的相关文件(包括plugin.xml)打包进你的插件JAR。
  2. maven-shade-plugin在打包时没有过滤掉其他插件的plugin.xml,导致它覆盖了你自己插件生成的描述符。

具体解决方案

1. 调整maven-resources-plugin的依赖范围

你不需要把maven-resources-plugin打包进自己的插件里,Maven运行时会自动提供它的相关依赖。修改依赖的scope为provided:

<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
  <scope>provided</scope>
</dependency>

2. 修改maven-shade-plugin配置,保留自己的插件描述符

在shade插件的filters里,排除所有第三方插件的plugin.xml,只保留你自己插件的这个文件:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>${maven-shade-plugin.version}</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <filters>
          <!-- 排除所有第三方JAR的签名文件和plugin.xml -->
          <filter>
            <artifact>*:*</artifact>
            <excludes>
              <exclude>META-INF/*.SF</exclude>
              <exclude>META-INF/*.DSA</exclude>
              <exclude>META-INF/*.RSA</exclude>
              <exclude>META-INF/maven/plugin.xml</exclude>
            </excludes>
          </filter>
          <!-- 单独保留自己插件的plugin.xml -->
          <filter>
            <artifact>com.xmaven:pig-maven-plugin</artifact>
            <includes>
              <include>META-INF/maven/plugin.xml</include>
            </includes>
          </filter>
        </filters>
      </configuration>
    </execution>
  </executions>
</plugin>

3. 确保maven-plugin-plugin正确生成描述符

你的POM里已经配置了maven-plugin-plugin生成descriptor和helpmojo,这个配置是没问题的,但要确保它的执行在shade之前(默认process-classes阶段在package阶段之前,所以顺序是对的)。如果还是有问题,可以尝试明确绑定到process-classes阶段:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-plugin-plugin</artifactId>
  <version>3.4</version>
  <executions>
    <execution>
      <id>default-descriptor</id>
      <phase>process-classes</phase>
      <goals>
        <goal>descriptor</goal>
      </goals>
    </execution>
    <execution>
      <id>help-descriptor</id>
      <phase>process-classes</phase>
      <goals>
        <goal>helpmojo</goal>
      </goals>
    </execution>
  </executions>
</plugin>

最后验证

执行以下命令重新打包并安装插件:

mvn clean install

然后在你的项目中重新使用插件,这个错误应该就会消失了。

内容的提问来源于stack exchange,提问作者shiv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:30:49