Maven shade plugin configuration not replacing the package

百般思念 提交于 2020-03-03 14:00:09

问题


Based on the requirement at Maven dependency incompatible library class, I have tried shade plugin as like below, but went in vain.

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

My target here is to replace the package with of a.b.c structure with x.y.z of classes. Did I miss any crucial configurations here?


回答1:


To replace the package a.b.c with x.y.z on your shaded jar you should add the relocations entry as follow on maven-shade-plugin:

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


来源:https://stackoverflow.com/questions/60399179/maven-shade-plugin-configuration-not-replacing-the-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!