I'm packaging a Spring Boot app into an uber jar using the maven-shade plugin. Simple, right? Well, it is except as of recently I'm getting the following warning at the end of mvn clean package
:
[WARNING] Discovered module-info.class. Shading will break its strong encapsulation.
It's not actually breaking anything but I'm a perfectionist and this is driving me nuts. How do I get rid of it? I've tried many things without success.
Shading is a process where a dependency is relocated to a different Java package and copied into the same JAR file as the code that relies on that dependency. The main purpose of shading is to avoid conflicts between the versions of dependencies used by a library and the versions used by the consumers of that library.
maven-shade-plugin : It packages all dependencies into one uber-jar. It can also be used to build an executable jar by specifying the main class. This plugin is particularly useful as it merges content of specific files instead of overwriting them by Relocating Classes.
Short Answer. The dependency-reduced-pom. xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.
Filtering out the file in the shade plugin seems to work fine for me.
Here's what my maven-shade-plugin
config looks like:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.1</version> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>module-info.class</exclude> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin>
The key line is the <exclude>module-info.class</exclude>
. The filter excludes that file whenever it sees it, in any artifact (*:*
= any artifact). (The other three excludes I use to get rid of bugs with signature files in dependencies)
I haven't noticed any unwanted side effects from doing this, and the warning is now gone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With