Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same dependency as "ejb" and "jar" - what happens?

Dependencies in Maven have a type element which defaults to jar, but can be set to ejb, war, ear, etc. The type ejb is a special case because it does not lead to a different file ending: The ejb has still the ending .jar.

I have an ear project where the same dependency is referenced once with type ejb and once with type jar (in the transitive dependency tree). Both entries ask for the very same file, with different Maven "coordinates".

From the perspective of the dependencyConvergence rule of the enforcer plugin, both dependencies seem to be different - the version of the <type>jar dependency is seemingly not managed by dependencyManagement. Nevertheless, only one of the dependencies makes it into the ear - namely the <type>ejb one.

When does Maven "drop" the second dependency and what can I do to influence this?

Please note: I know that you shouldn't have ejbs as jars on your dependency list, but if I kill the responsible developers, I might go to prison.

like image 344
J Fabian Meier Avatar asked Feb 15 '17 13:02

J Fabian Meier


1 Answers

I created two sample projects in Eclipse: one EAR, one EJB.

If the order in the EAR's POM is:

<dependency>
  ...
  <type>jar</type>

<dependency>
  ...
  <type>ejb</type>

the ejb.jar is put to .ear's /lib only.

If the order in the EAR's POM is:

<dependency>
  ...
  <type>ejb</type>

<dependency>
  ...
  <type>jar</type>

the ejb.jar is put to .ear's root and /lib.

Apparently one of the rare cases where order of declaration in the POM matters.

BTW, just to make it clear: Your "the same dependency is referenced [...] with different Maven 'coordinates'" is contradicting. Maven coordinates are groupId, artifactId and version (GAV), not packaging and/or classifier, because the latter two don't specify the "Where?" but the "What?". It's probably that why you quoted "coordinates".

like image 146
Gerold Broser Avatar answered Nov 05 '22 08:11

Gerold Broser