I had the exact same issue and here is what I did to make it work.
My project was including a "ThatProject" library containing a ServiceFactory.java class causing a bug.
<dependencies>
<dependency>
<groupId>com.example.ThatGroup</groupId>
<artifactId>ThatProject</artifactId>
<version>${ThatProject.version}</version>
</dependency>
</dependencies>
In my own project I created a same class to shadow the one of "ThatProject" (the path must match).
→ src\main\java\com\example\ThatGroup\ThatProject\ServiceFactory.java
In my pom.xml I used the maven-shade-plugin plugin as follows.
Please note how I am excluding the original ServiceFactory.java from the "ThatProject" library.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Include all dependencies in JAR -->
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>shade</id>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>com.example.ThatGroup:ThatClient</artifact>
<excludes>
<exclude>com/example/ThatGroup/ThatProject/ServiceFactory.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And that's it, it finally worked for me. In my case I was including all the files of my project with this configuration of pom.xml (including my shadowing version of ServiceFactory.java).
As mentioned, the original ServiceFactory.java was excluded during the maven build.
Hope this helps!