Declare dependency in section even if dependency not used everywhere?

后端 未结 6 469
醉酒成梦
醉酒成梦 2021-01-31 10:23

We\'re using maven 2.1.0. I have multiple modules that are completely separate, but still have many common dependencies. Like log4J, but some modules don\'t need it. I am wond

6条回答
  •  臣服心动
    2021-01-31 11:17

    We use a single common parent with a dependencyManagement block for all our projects. This is starting to break down as we move more projects into maven - if a project needs a different version then we have to either declare it as a dependency for all children or explicitly define the version for each pertinent child.

    We're trying out a model where we split the dependencyManagement out from our common parent and then import our corporate dependencyManagement pom into the top level project pom. This allows us to selectively define project defaults that override the corporate defaults.

    Here is the original scenario:

    A   defines version 1.0 of foo.jar as the corporate default
    B   child of A
    C1, C2, C3  children of B
    D1, D2, D3 children of C1, C2, C3 respectively
    

    If D1 and D2 require version 1.1 of foo.jar, then our choice used to be:

    1. Declare foo.jar version 1.1 as a dependency in B, making it appear that C1, C2, C3 and D3 also depended upon version 1.1
    2. Declare foo.jar version 1.1 as a dependency in D1 and D2, moving the dependency declaration into multiple places deeper in our project hierarchy.

    Here is what we're trying out:

    A   defines version 1.0 of foo.jar as the corporate default
    B   dependencyManagement: imports A, declares a default of foo.jar version 1.1
    C1, C2, C3  children of B
    D1, D2, D3 children of C1, C2, C3 respectively
    

    Now D1 and D2 just declare a dependency upon foo.jar and pick up version 1.1 from the dependencyManagement block of B.

提交回复
热议问题