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

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

To remove the module-info.class warning when shading (repackaging) a JAR using tools like Apache Maven Shade Plugin or Gradle Shadow Plugin, you typically need to take specific actions to handle the module-info.class file appropriately. This warning occurs because the module-info.class file is part of the Java module system introduced in Java 9 and later, and it may not be automatically handled by the shading process. Here's how you can address this warning:

  1. Exclude module-info.class:

    When shading a JAR, you can exclude the module-info.class file explicitly from the shading process. Below are examples for both Maven and Gradle:

    Maven: In your Maven pom.xml, add an exclusion for module-info.class within the <configuration> section of the maven-shade-plugin:

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <!-- Adjust the version as needed --> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>module-info.class</exclude> </excludes> </filter> </filters> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

    Gradle: In your Gradle build.gradle file, exclude module-info.class within the shadowJar task configuration:

    shadowJar { exclude 'module-info.class' } 
  2. Upgrade to a Shade Plugin Version with Improved Module Info Handling:

    Some versions of the Maven Shade Plugin and Gradle Shadow Plugin have improved handling of module-info.class. Consider upgrading to a more recent version of the shading plugin to see if the warning is addressed automatically.

  3. Check Dependencies:

    Ensure that your project's dependencies don't contain their own module-info.class files. If they do, you may need to configure the shading process to exclude those files from dependencies as well.

  4. Review Shading Configuration:

    Double-check your shading configuration to make sure it's not inadvertently including module-info.class files from dependencies. Ensure that the shading process is properly configured to exclude them.

  5. Disable Module System (Java 8 and earlier):

    If your project is not using the Java module system and you are working with Java 8 or earlier, you can also consider using an older version of the shading plugin that doesn't produce this warning.

By following these steps and ensuring that the module-info.class file is excluded from the shading process, you should be able to remove the warning related to module-info.class in your shaded JAR.


More Tags

element-ui renaming ado genfromtxt common-table-expression knitr event-listener callstack multiplication arcore

More Java Questions

More Chemistry Calculators

More Auto Calculators

More Everyday Utility Calculators

More Livestock Calculators