Dependency Mechanism
๋ค์ด๊ฐ๋ฉฐ
- ํ๋์ ํ๋ก์ ํธ์ ์์กด์ฑ์ ๊ด๋ฆฌํ๋๊ฒ์ ๋งค์ฐ ์ฝ๋ค.
- ํ์ง๋ง ์ฌ๋ฌ๊ฐ์ ๋ชจ๋์ ๊ฐ์ง ํ๋ก์ ํธ์์ ์์กด์ฑ์ ๊ด๋ฆฌํ๋ ์ผ์ ์ด๋ ค์ด ์ผ์ด๋ค.
- ์ด๋ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์๋์ ๊ฐ์ ์ ๋ต๋ค์ด ๋ฑ์ฅํ๊ฒ ๋๋ค.
Transitive Dependency๋?
- ์์กด์ฑ์ ์ถ๊ฐํ๋ฉด ํด๋น ์์กด์ฑ์ด ๊ฐ์ง ์์กด์ฑ๋ ํจ๊ป ํฌํจ๋์ด์ ๊ฐ์ ธ์ค๊ฒ ๋๋ค.
- ๊ทธ๋ ๊ฒ ๊ฐ์ด ํฌํจ๋์ด์ ๊ฐ์ ธ์ค๊ฒ ๋ ์์กด์ฑ์ Transitive Dependecy๋ผ๊ณ ํ๋ค.
Dependency Mediation์ด๋?
- ์ฌ๋ฌ๊ฐ์ง ์์กด์ฑ์ ๋ง๋๋ ๊ฒฝ์ฐ ์ด๋ ์์กด์ฑ์ ์ ํํ๋์ง์ ๋ํ ์ ๋ต์ด๋ผ๊ณ ๋ณผ ์ ์๋ค.
- ์๋์ ๊ฐ์ ์์กด์ฑ ์ํฉ์ ๋ง๋ฌ๋ค๊ณ ๊ฐ์ ํด๋ณด์
A
โโโ B
โ โโโ C
โ โโโ D 2.0
โโโ E
โโโ D 1.0
-
Maven์ ๊ฐ์ฅ ๋ฎ์ Depth์ ์์กด์ฑ์ ์ฑํํ๋ ์ ๋ต์ ์ ํํ๊ณ ์๋ค.
- ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ Dependency D๋ A โ E๋ก ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ์ ํํ๊ณ 1.0์ ๊ฐ์ ธ์จ๋ค.
-
1.0 ๋์ 2.0์ ๊ฐ์ ธ์ค๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ์ด๋ป๊ฒ ํด์ผ ํ ๊น?
- ๋ค์๊ณผ ๊ฐ์ด ๋ช ์์ ์ผ๋ก ์ ์ธํ๋๊ฒ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ด๋ค.
- ๊ฐ์ฅ ๋ฎ์ Depth์ ์์กด์ฑ์ธ 2.0์ ์ ํํ๊ณ ๊ฐ์ ธ์จ๋ค.
A
โโโ B
โ โโโ C
โ โโโ D 2.0
โโโ E
โ โโโ D 1.0
โ
โโโ D 2.0
Dependency Management์ด๋?
- ๋ค์๊ณผ ๊ฐ์ 2๊ฐ์ pom.xml์ด ์๋ค๊ณ ๊ฐ์ ํด๋ณด์.
- ๋ถ๋ชจ์ XML
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>A</artifactId>
<packaging>pom</packaging>
<name>A</name>
<version>1.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>d</artifactId>
<version>1.2</version> <!-- ๋ถ๋ชจ๋ 1.2 Version -->
</dependency>
</dependencies>
</dependencyManagement>
</project>
- ๋ถ๋ชจ๋ฅผ ์์๋ฐ์ ์์ XML
<project>
<parent>
<artifactId>A</artifactId>
<groupId>maven</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>B</artifactId>
<packaging>pom</packaging>
<name>B</name>
<version>1.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>d</artifactId>
<version>1.0</version> <!-- ๋ถ๋ชจ์ Version ๋์ ์ง์ ๋ฒ์ ผ์ ๋ช
์ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
- ๋ถ๋ชจ๊ฐ ์ ์ธํ Dependency D์ ๋ํด์ ์์์ 1.0์ผ๋ก dependencyManagement๋ฅผ ํตํด ๊ด๋ฆฌํ๊ณ ์๋ค.
- ํ๋ก์ ํธ์์ ๊ฐ๋ฐ์๊ฐ ์ง์ ์ ์ผ๋ก ๋ฒ์ ผ์ ์ง์ ์ ์ผ๋ก ๋ช ์ํด์ฃผ๋ ๊ฒ์ด๋ค.
๊ทธ๋ฅ dependencies์ ์ถ๊ฐํ๋ฉด dependency mediation์ ํตํด ํด๊ฒฐํ ์ ์๋๊ฒ์ด ์๋๊ฐ?
- dependencyManagement์ dependencies ์ฐจ์ด์ ์ด ์กด์ฌํ๋ค.
- dependencyManagement๋ ์์กด์ฑ์ด ์ถ๊ฐ๋์์ ๋ ์ํ๋๋ค.
- ์ฆ ์์์ด ์์กด์ฑ์ ์์๋ฐ์ ์์ฑํ์ฌ๋ ์์กด์ฑ ์ํฅ์ ์๋ค.
- dependencies๋ ์์์ ์์กด์ฑ๊น์ง ์ํฅ์ ๋ฏธ์น๊ธฐ ๋๋ฌธ์ ์ฃผ์ํด์ ์ฌ์ฉํด์ผ ํ๋ค.
- ์์๋ฐ๋ ๋ชจ๋ ์์กด์ฑ์ด dependencyManagement๋ฅผ ์ ์ธํด์ผํ๋ ์ํฉ์ด ์ค๊ฒ ๋๋ค.
Reference
- https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
- https://docs.gradle.org/current/userguide/dependency_management.html
- https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html#sec:configurations_java_tutorial
- https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
- https://kwonnam.pe.kr/wiki/gradle/from_maven