Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven same Classname in different dependencies

i have a maven project that has two dependencies: DependencyA and DependencyB. In each of the dependencies there is a class, lets call it FooClass.

Now there is a problem, because one class of my project needs the FooClass of DependencyA and another class needs the FooClass of DependencyB. But both classes load the FooClass of DependencyA.

Can i solve this problem with maven? Or do i have to think about the design of my project structure?

like image 487
smsnheck Avatar asked May 12 '26 14:05

smsnheck


2 Answers

You should avoid getting two classes with same name in same package. This would lead to the idea that you have two modules of different versions of one code...

It would not be an issue if you had for instance com.yourcompany.yourproyectA.FooClass and com.yourcompany.yourproyectB.FooClass.

This scenario happens often and I have never had an issue with maven.

Regards

like image 88
Martin Avatar answered May 14 '26 05:05

Martin


If two libraries need two different versions of the same library, I recommend to use a module system such as OSGi.

like image 35
Puce Avatar answered May 14 '26 05:05

Puce