Missing Abstract Class using Maven Shade Plugin for Relocating Classes

喜夏-厌秋 提交于 2020-08-10 19:34:12

问题


I am currently using Maven Shade plugin to relocate classes but it comes with the following issue:

My project has a dependency on netty-all package:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.51.Final</version>
</dependency>

Due to a version conflict issue on this netty package, I need to relocate the classes within netty to avoid this conflict. I was trying to relocate classes from io.netty to com.shaded.io.netty using the plugin configurations below:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>io.netty</pattern>
                                    <shadedPattern>com.shaded.io.netty</shadedPattern>
                                </relocation>
                            </relocations>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>shaded</shadedClassifierName>
                            <transformers>
                                <transformer
                                     implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

After running mvn clean package and running the code, it throws:

java.lang.NoClassDefFoundError: com/shaded/io/netty/util/internal/ObjectPool$ObjectCreator

Then I use jar -tf <my-shaded-jar-file-name> to view what's been packed into the final shaded jar, but cannot find ObjectPool class (which is an abstract class) in com/shaded/io/netty/util/internal/ directory while other classes seem to be successfully relocated into here.

Not sure if anything is missing here in the pom file that caused this issue?

来源:https://stackoverflow.com/questions/63024448/missing-abstract-class-using-maven-shade-plugin-for-relocating-classes

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