Should all 3rd-party jar dependencies be introduced to Maven via 'import' scope?

StackOverflow https://stackoverflow.com/questions/19880278

  •  30-07-2022
  •  | 
  •  

Question

So confused about import scoping in Maven. It seems to imply that all 3rd-party jar dependencies in a large, muti-module project would benefit from being dependency managed in the parent using the 'import' scope. Is that correct?

Était-ce utile?

La solution

From maven's documentation about the import scope:

This scope is only used on a dependency of type pom in the section. It indicates that the specified POM should be replaced with the dependencies in that POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

Frankly, this is usually isn't a very useful scope, and in any event it is not relevant for 3rd party jar dependencies - only for 3rd party pom dependencies. Where you place dependencies is somewhat a matter of taste, but the practice I found worked best for me was to place all the dependencies in the "lowest common denominator" pom's <dependencyManagement> section, and then referencing them in the <dependencies> section of the specific subprojects as needed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top