I am trying to remove a few classes from a dependency. I have tried using the following configuration in the pom.xml file but it is not working. The classes are still present in the fat jar. Can anyone help me with this?
I thought maybe they are present during the compile
time, so I tried package
but they are still present.
My intention is to remove the Event
and BaseEvent
classes from the models
dependency.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.mua.dev</groupId>
<artifactId>learn</artifactId>
<version>1.0.5</version>
<name>Learn</name>
<description>Learning Maven</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.mua.dev</groupId>
<artifactId>models</artifactId>
<version>1.6.8</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -XepOpt:NullAway:AnnotatedPackages=org.mua</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.23.0</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>0.10.15</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>org.mua.dev:models</artifact>
<excludes>
<exclude>org/mua/dev/models/Event.class</exclude>
<exclude>org/mua/dev/models/BaseEvent.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>util</id>
<url>https://nexus.mua.test.mydomain.bd/repository/mua/</url>
</repository>
</repositories>
</project>
It will even work for me if we can specifically include only the classes I want to include. Let’s say I want to keep all dto
in the below structure and remove all entity
classes, and specifically EventEntity
class.
models
- dto
- EventDto
- SomeOtherDto
- AnotherDto
- YetAnotherDto
- entity
- EventEntity
- SomeOtherEntity
- AnotherEntity
- YetAnotherEntity
Any help will be appreciated. Thanks in advance.
2
The configuration you provided looks correct, but here are a few things to double-check:
-
Make sure the class paths are correct in the
<exclude>
or
<include>
sections of the Maven Shade Plugin configuration. -
Ensure that the maven-shade-plugin is
executing after everything else in the build lifecycle (specifically
during the package phase). -
Try cleaning and rebuilding the project to
remove any old artifacts that might still include the classes:mvn clean package
-
Use the following command to inspect the
jar and ensure only the expected classes are included:jar -tf <your-jar-file>