Differences between dependencyManagement and dependencies in Maven

前端 未结 13 1392
北荒
北荒 2020-11-22 04:14

What is the difference between dependencyManagement and dependencies? I have seen the docs at Apache Maven web site. It seems that a dependency def

13条回答
  •  余生分开走
    2020-11-22 05:05

    There's still one thing that is not highlighted enough, in my opinion, and that is unwanted inheritance.

    Here's an incremental example:

    I declare in my parent pom:

    
            
                com.google.guava
                guava
                19.0
            
    
    

    boom! I have it in my Child A, Child B and Child C modules:

    • Implicilty inherited by child poms
    • A single place to manage
    • No need to redeclare anything in child poms
    • I can still redelcare and override to version 18.0 in a Child B if I want to.

    But what if I end up not needing guava in Child C, and neither in the future Child D and Child E modules?

    They will still inherit it and this is undesired! This is just like Java God Object code smell, where you inherit some useful bits from a class, and a tonn of unwanted stuff as well.

    This is where comes into play. When you add this to your parent pom, all of your child modules STOP seeing it. And thus you are forced to go into each individual module that DOES need it and declare it again (Child A and Child B, without the version though).

    And, obviously, you don't do it for Child C, and thus your module remains lean.

提交回复
热议问题