๐ Gradle์ด๋?
Gradle์ ๋น๋ ์๋ํ ๋๊ตฌ๋ก, ์์กด์ฑ ๊ด๋ฆฌ์ ํ๋ก์ ํธ ๋น๋๋ฅผ ํจ์จ์ ์ผ๋ก ์ํํ ์ ์๋๋ก ๋์์ค๋๋ค.
์๋ฐ(Java), ์ฝํ๋ฆฐ(Kotlin), ์๋๋ก์ด๋(Android), ์คํ๋ง ๋ถํธ(Spring Boot) ๋ฑ ๋ค์ํ ํ๋ก์ ํธ์์ ์ฌ์ฉ๋ฉ๋๋ค.
1. Gradle์ ํน์ง
1-1. ์์กด์ฑ(Dependency) ๊ด๋ฆฌ
- build.gradle ํ์ผ์์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ์ธํ๋ฉด, ์๋์ผ๋ก ๋ค์ด๋ก๋ํ๊ณ ํ๋ก์ ํธ์ ์ ์ฉํฉ๋๋ค.
- ์์ (Spring Boot)
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
1-2. DSL(Domain Specific Language) ์ฌ์ฉ
Gradle์ Groovy ๋๋ Kotlin DSL์ ์ฌ์ฉํ์ฌ ์ค์ ์ ์์ฑํ ์ ์์ต๋๋ค.
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
- Kotlin DSL ์ฌ์ฉ (build.gradle.kts)
plugins {
kotlin("jvm") version "1.6.21"
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
}
1-3. ๋ฉํฐ ๋ชจ๋ ๋น๋ ์ง์
- ํ๋์ ํ๋ก์ ํธ์์ ์ฌ๋ฌ ๊ฐ์ ์๋ธ ๋ชจ๋(Submodule) ์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
- ์์
rootProject
โโโ app
โโโ core
โโโ data
rootProject.name = 'MyProject'
include 'app', 'core', 'data'
- ๊ฐ๊ฐ์ ๋ชจ๋(app, core, data)์ ๋
๋ฆฝ์ ์ผ๋ก ๊ฐ๋ฐํ๋ฉด์๋ ํ๋์ ํ๋ก์ ํธ๋ก ๋น๋ ๊ฐ๋ฅ.
1-4. ๋ณ๋ ฌ ๋น๋ ๋ฐ ์บ์ฑ (์๋ ์ต์ ํ)
- ์ด์ ๋น๋ ๊ฒฐ๊ณผ๋ฅผ ์บ์ฑํ์ฌ ์ฌ์ฌ์ฉํ๊ณ , ๋ณ๋ ฌ ๋น๋๋ฅผ ์ง์ํ์ฌ ์๋๋ฅผ ์ต์ ํํฉ๋๋ค.
- ๋ช
๋ น์ด ์์:
gradle build --parallel --build-cache
2. Gradle ์ฃผ์ ๋ช
๋ น์ด
๋ช
๋ น์ด |
์ค๋ช
|
gradle build |
ํ๋ก์ ํธ ๋น๋ |
gradle clean |
๋น๋ ์บ์ ์ญ์ |
gradle test |
ํ
์คํธ ์คํ |
gradle dependencies |
์์กด์ฑ ํ์ธ |
gradle tasks |
์ฌ์ฉ ๊ฐ๋ฅํ ์์
๋ชฉ๋ก ํ์ธ |
3. Gradle๊ณผ Maven ๋น๊ต
๋น๊ต ํญ๋ชฉ |
Gradle |
Maven |
์ค์ ๋ฐฉ์ |
Groovy/Kotlin DSL |
XML(POM) |
๋น๋ ์๋ |
๋น ๋ฆ (์บ์ฑ ๋ฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ ์ง์) |
๋๋ฆผ |
์ ์ฐ์ฑ |
๋์ (์ปค์คํ
๊ฐ๋ฅ) |
๋ฎ์ (์ ํํ๋ ๊ตฌ์กฐ) |
์์กด์ฑ ๊ด๋ฆฌ |
๊ฐ๋ ฅํ DSL ์ ๊ณต |
XML ๊ธฐ๋ฐ |
๐ Gradle์ ์ ์ฐํ๊ณ ๋น ๋ฅธ ๋น๋๊ฐ ํ์ํ ๋ ์ ์ฉํ๋ฉฐ, Maven์ ๊ตฌ์กฐ๊ฐ ์ ํํ๋ ํ๋ก์ ํธ์ ์ ํฉํฉ๋๋ค.
4. Gradle์ด ๋ง์ด ์ฌ์ฉ๋๋ ๊ณณ
โ
Spring Boot → gradle.build๋ก ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฐ ์์กด์ฑ ๊ด๋ฆฌ
โ
Android ๊ฐ๋ฐ → Gradle์ด ๊ณต์ ๋น๋ ๋๊ตฌ
โ
๋ฉํฐ ๋ชจ๋ ํ๋ก์ ํธ → ์ฌ๋ฌ ๊ฐ์ ๋ชจ๋์ ํฌํจํ๋ ํ๋ก์ ํธ์์ ๊ฐ๋ ฅํ ์ฑ๋ฅ ์ ๊ณต
๐ ์ ๋ฆฌ
- Gradle์ ๋น๋ ์๋ํ ๋๊ตฌ์ด๋ฉฐ, ๋น ๋ฅธ ๋น๋ ์๋์ ์ ์ฐ์ฑ์ ์ ๊ณตํจ.
- Groovy ๋๋ Kotlin DSL์ ์ฌ์ฉํ์ฌ ์ค์ .
- ์์กด์ฑ ๊ด๋ฆฌ ๋ฐ ๋ฉํฐ ๋ชจ๋ ๋น๋ ์ง์.
- Maven๋ณด๋ค ์๋๊ฐ ๋น ๋ฅด๊ณ ํ์ฅ์ฑ์ด ๋ฐ์ด๋จ.