1

I have 2 dependencies that have identical pathname for a class.

Like:

import com.a.b.c.d.e.f.MyClass; // this exists in both dependency-1 and dependency-2

When I install both dependencies, I end with errors. (Works fine if I use only 1 dependency).
I need both cos I need other packages in the 2nd dependency.

Inside my maven pom file.

// only had this in the past so no issues
<dependency>
    <groupId>com.a.b</groupId>
    <artifactId>dependency-1</artifactId>
    <version>${some.version}</version>
</dependency>

// now adding this cos I need to use some other classes in here. 
<dependency>
    <groupId>com.a.b</groupId>
    <artifactId>dependency-2</artifactId>
    <version>${another.version}</version>
</dependency>

Is there a way to ask to exclude just that class causing issues?

I know I can exclude another dependency inside here. But can I exclude just this class that's causing issues.
Or at least exclude the package com.a.b.c.d.e.f?

Can't use maven shade either considering both dependencies have the same package name and class.

Pls advice or if there is a better solution to this.
To note, I can't amend these 2 dependencies.

Update:

As mentioned above. maven shade is not applicable here.

karvai
  • 2,417
  • 16
  • 31

1 Answers1

0

There is no straightforward solution to your problem.

Java load all classes in single classloader by default.

You may try to create custom clasloader and load class you want, but it is complex task.

You may load one of your dependencies manually in separate class loader, it will require changes in deployment.

talex
  • 17,973
  • 3
  • 29
  • 66