【问题标题】:Maven shade plugin configuration not replacing the packageMaven shade插件配置不替换包
【发布时间】:2020-02-25 16:28:43
【问题描述】:

根据Maven dependency incompatible library class的要求,我尝试了如下的shade插件,但没有成功。

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
    <execution>
        <phase>compile</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <filters>
                <filter>
                    <artifact>com.lib:Encoder</artifact>
                    <includes>
                        <include>x/y/z/**</include>
                    </includes>
                    <excludes>
                        <exclude>a/b/c/**</exclude>
                    </excludes>
                </filter>
            </filters>
        </configuration>
    </execution>
</executions>

我的目标是用 x.y.z 的类替换 a.b.c 结构的包。 我错过了这里的任何关键配置吗?

【问题讨论】:

标签: maven maven-shade-plugin


【解决方案1】:

要在阴影 jar 上用 x.y.z 替换包 a.b.c,您应该在 maven-shade-plugin 上添加 relocations 条目,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <minimizeJar>true</minimizeJar>
                <relocations>
                    <relocation>
                        <pattern>x.y.z</pattern>
                        <shadedPattern>a.b.c</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </execution>
    </executions>
</plugin>

【讨论】:

  • 仍然面临同样的失败。此外,我也尝试了带有“安装”的 。还没有运气!
  • 你面临什么样的失败?可以分享一下细节吗?
  • /cannot access a.b.c.Template [ERROR] class file for a.b.c.Template not found
  • 它是用于 - mvn install
猜你喜欢
  • 2014-07-23
  • 2012-01-31
  • 2013-05-07
  • 2020-01-02
  • 1970-01-01
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
  • 2015-02-05
相关资源
最近更新 更多