Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove module-info.class warning for a shaded .jar?

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.

like image 921
Albert Rannetsperger Avatar asked May 09 '19 16:05

Albert Rannetsperger


People also ask

What is a shaded jar Java?

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.

What is Maven shaded jar?

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.

What is dependency reduced POM?

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.


1 Answers

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!

like image 119
rococo Avatar answered Sep 18 '22 08:09

rococo