Skip to content

Latest commit

ย 

History

History
78 lines (73 loc) ยท 3.07 KB

6.Project Inheritance vs Project Aggregation.md

File metadata and controls

78 lines (73 loc) ยท 3.07 KB
Project Inheritance vs Project Aggregation(ํ”„๋กœ์ ํŠธ ์ƒ์† ๋Œ€ ํ”„๋กœ์ ํŠธ ์ง‘๊ณ„)

์—ฌ๋Ÿฌ Maven ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๊ณ  ๋ชจ๋‘ ๋น„์Šทํ•œ ๊ตฌ์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋ฉด
์œ ์‚ฌํ•œ ๊ตฌ์„ฑ์„ ์ œ๊ฑฐํ•˜๊ณ  ๋ถ€๋ชจ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฆฌํŒฉํ† ๋ง ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ๋‹น์‹ ์ดํ•ด์•ผ ํ•  ๊ฒƒ์€ ๋‹น์‹ ์˜ Maven ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์œ„ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์† ํ•  ์ˆ˜ ์žˆ๋„๋กํ•˜๋Š” ๊ฒƒ๋ฟ์ž…๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ์„ค์ •์€ ๋ชจ๋“  ํ”„๋กœ์ ํŠธ์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

ํ•จ๊ป˜ ๊ตฌ์ถ•๋˜๊ฑฐ๋‚˜ ์ฒ˜๋ฆฌ๋˜๋Š” ํ”„๋กœ์ ํŠธ ๊ทธ๋ฃน์ด์žˆ๋Š” ๊ฒฝ์šฐ
์ƒ์œ„ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ํ•ด๋‹น ์ƒ์œ„ ํ”„๋กœ์ ํŠธ์—์„œ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋ฅผ ๋ชจ๋“ˆ๋กœ ์„ ์–ธํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ ‡๊ฒŒํ•จ์œผ๋กœ์จ, ๋‹น์‹ ์€ ๋‹จ์ง€ ๋ถ€๋ชจ๋ฅผ buildํ•˜๋ฉด๋˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ๋’ค๋”ฐ๋ผ ์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ฌผ๋ก  Project Inheritance์™€ Project Aggregation์„ ๋‘˜ ๋‹ค ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ฆ‰, ๋ชจ๋“ˆ์—์„œ ๋ถ€๋ชจ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง€์ •ํ•˜๋„๋กํ•˜๊ณ  ๋™์‹œ์— ํ•ด๋‹น ๋ถ€๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ ํ•ด๋‹น Maven ํ”„๋กœ์ ํŠธ๋ฅผ ๋ชจ๋“ˆ๋กœ ์ง€์ •ํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์„ธ ๊ฐ€์ง€ ๊ทœ์น™์„ ๋ชจ๋‘ ์ ์šฉํ•˜๋ฉด๋ฉ๋‹ˆ๋‹ค.

  • ๋ถ€๋ชจ POM์˜ ๋ชจ๋“  ํ•˜์œ„ POM์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
  • ์ƒ์œ„ POM ํŒจํ‚ค์ง•์„ ๊ฐ’ "pom"์œผ๋กœ ๋ณ€๊ฒฝํ•˜์‹ญ์‹œ์˜ค.
  • ์ƒ์œ„ POM์— ๋ชจ๋“ˆ์˜ ๋””๋ ‰ํ† ๋ฆฌ (ํ•˜์œ„ POM)๋ฅผ ์ง€์ •ํ•˜์‹ญ์‹œ์˜ค.

The Scenario(์‹œ๋‚˜๋ฆฌ์˜ค)
์ด์ „์˜ original artifact POM์„ ๋‹ค์‹œ ๊ฐ์•ˆํ•  ๋•Œ,
com.mycompany.app:my-app:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

com.mycompany.app:my-module:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-module</artifactId>
  <version>1</version>
</project>

and this directory structure(๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ)

.
 |-- my-module
 |   `-- pom.xml
 `-- parent
     `-- pom.xml

The Solution(ํ•ด๊ฒฐ์ฑ…) ํ”„๋กœ์ ํŠธ ์ƒ์†๊ณผ ์ง‘๊ณ„๋ฅผ ๋ชจ๋‘ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด ์„ธ ๊ฐ€์ง€ ๊ทœ์น™ ๋งŒ ์ ์šฉํ•˜๋ฉด๋ฉ๋‹ˆ๋‹ค.
com.mycompany.app:my-app:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <packaging>pom</packaging>
 
  <modules>
    <module>../my-module</module>
  </modules>
</project>

com.mycompany.app:my-module:1's POM

<project>
  <parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1</version>
    <relativePath>../parent/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-module</artifactId>
</project>

์ฐธ๊ณ  : ์ƒ์†์€ POM ์ž์ฒด์— ์‚ฌ์šฉ ๋œ ๊ฒƒ๊ณผ ๋™์ผํ•œ ์ƒ์† ์ „๋žต์„ ํ”„๋กœํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค.