为什么maven shade插件的重新定位不起作用?

8wtpewkr  于 2021-05-30  发布在  Hadoop
关注(0)|答案(3)|浏览(421)

我在运行包含比hadoop发行版(cdh5.2)中包含的版本更新的guava的hadoop作业时遇到了一些问题。这是一个已知的问题。我试图通过使用maven shade插件对库进行着色来解决这个问题。因此,我在我的 pom.xml :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <relocations>
            <relocation>
              <pattern>com.google</pattern>
              <shadedPattern>thirdparty.com.google</shadedPattern>
            </relocation>
          </relocations>
        </configuration>
      </execution>
    </executions>
  </plugin>

不幸的是,阴影似乎不起作用。解压uberjar时,没有文件夹 thirdparty/com/google 但仍然是文件夹 com/google .
有人知道出了什么问题吗?

fnatzsnv

fnatzsnv1#

似乎您需要在重定位规则中引用包名,而不是maven groupid,我在lib中使用rxv1,不想用它污染用户的名称空间,下面的pom.xml部分重写字节码,因此最终的uberjar将有rx,但已重命名(shaded.rx)。
遮阳棚搬迁文件

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <relocations>
            <relocation>
              <pattern>rx</pattern>
              <shadedPattern>shaded.rx</shadedPattern>
            </relocation>
          </relocations>
        </configuration>
      </execution>
    </executions>
  </plugin>
m3eecexj

m3eecexj2#

您可能需要在下面指定显式artifactset::includes <configuration> 章节:

<configuration>
        <artifactSet>
            <includes>
                <include>com.google.guava:*</include>
                ...
            </includes>
        </artifactSet>
        <relocations>
        ...
nmpmafwu

nmpmafwu3#

这对我有用:

<relocations>
   <relocation>
     <pattern>com.google.</pattern>
     <shadedPattern>thirdparty.com.google.</shadedPattern>
   </relocation>
 </relocations>

注意图案末尾的点。

相关问题