• Dependency Mechanism
    DEV 2023. 12. 2. 11:44

    gear

     maven, gradle dependency tree

    • 아래와 같은 커맨드로 볼 수 있긴 하지만,,
      • mvn dependency:tree
      • gradle dependencies
    • 좀 더 편하게 볼 수 없나?

    view dependencies as a diagram

    • intellij 다이어그램 형태로 볼 수 있는 bundled plugins를 제공한다.
    • ultimate에서만 가능하다. 😓
    • Maven Extension, Gradle Extension bundled plugins

     

    maven dependency diagram

    Dependency Mechanism

     

    Maven – Introduction to the Dependency Mechanism

    Introduction to the Dependency Mechanism Dependency management is a core feature of Maven. Managing dependencies for a single project is easy. Managing dependencies for multi-module projects and applications that consist of hundreds of modules is possible.

    maven.apache.org

    nearest definition

    A

    ├── B

    │   └── C

    │       └── D 2.0

    └── E

        └── D 1.0

    • A -> B -> C -> D 2.0
    • A -> E -> D 1.0
    • D 1.0 이 빌드시 사용됨, A -> D까지 가는 길이 E로 가는 길이 더 가깝기 때문
    • (D 1.0 will be used when building A because the path from A to D through E is shorter.)

     

    A

    ├── B

    │   └── C

    │       └── D 2.0

    ├── E

    │   └── D 1.0

    └── D 2.0

    • D 2.0을 명시적으로 추가해 강제로 사용할 수 있다.
    • (You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0)

     

    same depth

    A

    ├── B

    │   └── C

    │       └── D 2.0

    └── E

        └── F

            └── D 1.0

    • 만약 두 버전이 같은 depth에 있다면 먼저 선언된 쪽을 사용
    • (if two dependency versions are at the same depth in the dependency tree, the first declaration wins.)

     

    A

    ├── logback-classic

    │       └── C

    │                └── logback-core 1.2.9

    ├── logstash-logback-encoder

    │       └── F

    │                 └── logback-core 1.2.3

    └── log-x

              └── logback-core 1.1.1

    • 만약 위와 같은 프로젝트가 있다면 logback-core버전은 1.1.1을 사용하게 되기 때문에,
    • 아래와 같이 명시적으로 선언을 해줘야 하고, exclusion 할 수도 있다.

     

    A

    ├── logback-classic

    │       └── C

    │               └── exclusion -> logback-core 1.2.9

    ├── logstash-logback-encoder

    │       └── F

    │               └── exclusion -> logback-core 1.2.3

    ├── log-x

    │       └── logback-core 1.1.1

    └── logback-core 1.2.9

    728x90

    'DEV' 카테고리의 다른 글

go.