0

I need to check the Maven dependency injection order automatically. In a Maven module I take two dependencies with the same classes name and package. One dependency should always have priority on the other one, this mean it have to be declared first because of the order of dependencies injection of Maven.

It's possible to verify it with the dependency tree but manually, I wish there is a way to check this automatically.

Do you know if it is possible to do this with Maven?

Rumoch
  • 61
  • 1
  • 5
  • It is not very clear what you are asking at all. If the classes do not have the same canonical name, they should not collide in most cases. Why would loading order matter? – rmlan May 03 '16 at 12:46
  • Because Maven take the first who is declared if two classes have the same canonical name. I will be sure there is always the patched one and not the one from the core. – Rumoch May 03 '16 at 13:00
  • Ok, then "for the core the package name is ch.a.product and for the patch the package name is ch.b.product" is confusing, as it would suggest that the classes do *not* have the same canonical name. – rmlan May 03 '16 at 13:06
  • I am sorry they are both in the same package and have the same name this is the reason why the Maven dependency injection order is important. I cannot change this. – Rumoch May 03 '16 at 13:20

1 Answers1

0

First of all, "dependency injection" is something completely different and unrelated: managed magical mechanisms to pass needed objects from "outside" when constructing objects.

Maven just compiles code with dependency jars in the classpath. Any variant of the monkeypatched classes should allow your code to be compiled identically, so (to minimize breakage) you should avoid duplicate or conflicting Maven dependencies.

Reliably loading your replacement classes at runtime when Maven is no longer involved is an entirely different problem, whose solution depends on how your application is packaged and executed. For example, the order of jars in a typical classpath list should be reliable, and most application servers offer ways to specify and override with one another various global and application-specific classpaths.

Lorenzo Gatti
  • 1,260
  • 1
  • 10
  • 15