๐Ÿ˜

Gradle ์น˜ํŠธ์‹œํŠธ

Gradle Wrapper(gradlew) ๋ช…๋ น์–ด, Kotlin/Groovy DSL, ์˜์กด์„ฑ ์Šค์ฝ”ํ”„, ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ๋ฐ ์„ฑ๋Šฅ ์ตœ์ ํ™” ๋ ˆํผ๋Ÿฐ์Šค

--views
๋‹จ์ˆ˜:
#gradle#build#java#kotlin#spring#wrapper#dependencies#jvm์ตœ์ข… ์—…๋ฐ์ดํŠธ: 2026-09-26

1. Gradle Wrapper (gradlew) ํ•ต์‹ฌ ๋ช…๋ น์–ด

๐Ÿ’ป ์‹œ์Šคํ…œ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์š”๊ตฌ์‚ฌ์–‘ (System Requirements)

ํ•ญ๋ชฉ์ตœ์†Œ ์‚ฌ์–‘ (Minimum)๊ถŒ์žฅ ์‚ฌ์–‘ (Recommended)์ฐธ๊ณ  ๋ฐ ๋น„๊ณ 
์šด์˜์ฒด์ œ (OS)Linux, macOS, Windows 10/11Ubuntu 22.04 LTS+, macOS (Apple Silicon), Windows 11POSIX ๋ฐ Windows ํ™˜๊ฒฝ ์ง€์›
CPU2 ์ฝ”์–ด ์ด์ƒ4 ์ฝ”์–ด ~ 8 ์ฝ”์–ด ์ด์ƒGradle ๋ณ‘๋ ฌ ๋นŒ๋“œ(--parallel) ๋ฐ ์ž‘์—… ๋ถ„์‚ฐ
๋ฉ”๋ชจ๋ฆฌ (RAM)2 GB ์ด์ƒ (Gradle Daemon ํž™ ์ตœ์†Œ 1 GB)4 GB ~ 8 GB ์ด์ƒ๋Œ€๊ทœ๋ชจ ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ ์‹œ 8GB+ ๊ถŒ์žฅ
๋””์Šคํฌ (Storage)2 GB ์ด์ƒ์˜ ์—ฌ์œ  ๊ณต๊ฐ„10 GB ~ 30 GB ์ด์ƒ์˜ SSDGradle ์บ์‹œ(~/.gradle), ์˜์กด์„ฑ JAR ๋ฐ ๋นŒ๋“œ ์‚ฐ์ถœ๋ฌผ
๋„คํŠธ์›Œํฌ / ๋Ÿฐํƒ€์ž„JDK 17, 21, 25 LTS (Gradle 8.10+ ๊ธฐ์ค€ Java 21/25 ๊ถŒ์žฅ)JAVA_HOME ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ํ•„์ˆ˜์•„์›ƒ๋ฐ”์šด๋“œ ์ธํ„ฐ๋„ท (Maven Central ๋‹ค์šด๋กœ๋“œ์šฉ)
# 1. ๋นŒ๋“œ ๋ฐ ํด๋ฆฐ
./gradlew build                 # ํ”„๋กœ์ ํŠธ ์ „์ฒด ์ปดํŒŒ์ผ, ํ…Œ์ŠคํŠธ ๋ฐ JAR ์•„ํ‹ฐํŒฉํŠธ ๋นŒ๋“œ
./gradlew clean build           # build/ ๋””๋ ‰ํ† ๋ฆฌ ์™„์ „ ์‚ญ์ œ ํ›„ ์ƒˆ๋กœ ๋นŒ๋“œ
./gradlew build -x test         # ํ…Œ์ŠคํŠธ ์‹คํ–‰์„ ๊ฑด๋„ˆ๋›ฐ๊ณ  ๋น ๋ฅธ ๋นŒ๋“œ ์ˆ˜ํ–‰

# 2. ์‹คํ–‰ ๋ฐ ์ปดํŒŒ์ผ๋งŒ ์ˆ˜ํ–‰
./gradlew bootRun               # Spring Boot ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ์ปฌ ์‹คํ–‰
./gradlew classes testClasses   # ์‹คํ–‰/ํŒจํ‚ค์ง• ์—†์ด ์†Œ์Šค ์ฝ”๋“œ ์ปดํŒŒ์ผ๋งŒ ๊ฒ€์ฆ

# 3. ๋ฐ๋ชฌ(Daemon) ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ
./gradlew --status              # ์‹คํ–‰ ์ค‘์ธ Gradle ๋ฐ๋ชฌ ์ƒํƒœ ๋ฐ PID ํ™•์ธ
./gradlew --stop                # ๋ฐฑ๊ทธ๋ผ์šด๋“œ์— ์ƒ์ฃผํ•˜๋Š” ๋ชจ๋“  Gradle ๋ฐ๋ชฌ ์ข…๋ฃŒ (๋ฉ”๋ชจ๋ฆฌ ์ •๋ฆฌ)

# 4. ์„ฑ๋Šฅ & ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ… ์˜ต์…˜
./gradlew build --parallel      # ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ๋ณ‘๋ ฌ ๋นŒ๋“œ๋กœ ๋นŒ๋“œ ์‹œ๊ฐ„ ๋Œ€ํญ ๋‹จ์ถ•
./gradlew build --refresh-dependencies # ์›๊ฒฉ ์ €์žฅ์†Œ ์˜์กด์„ฑ ์บ์‹œ ๊ฐ•์ œ ์žฌ๋‹ค์šด๋กœ๋“œ
./gradlew build --info --stacktrace   # ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ ์ƒ์„ธ ์ŠคํƒํŠธ๋ ˆ์ด์Šค ์ถœ๋ ฅ

2. ์˜์กด์„ฑ ์Šค์ฝ”ํ”„ (Dependency Configurations)

dependencies {
  // 1. implementation: ๋‚ด๋ถ€ ๊ตฌํ˜„์šฉ (์ปดํŒŒ์ผ ํด๋ž˜์ŠคํŒจ์Šค ์ „ํŒŒ X, ๋นŒ๋“œ ์†๋„ ๋ฐ ์บก์Аํ™” ์ตœ์ )
  implementation 'org.springframework.boot:spring-boot-starter-web'

  // 2. api: ์™ธ๋ถ€ ๋…ธ์ถœ์šฉ (์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๋‹ค๋ฅธ ๋ชจ๋“ˆ๋กœ ์˜์กด์„ฑ ์ „์ด ์ „ํŒŒ)
  api 'com.google.guava:guava:33.0.0-jre'

  // 3. compileOnly: ์ปดํŒŒ์ผ ์‹œ์—๋งŒ ํ•„์š”, ์ตœ์ข… ๋Ÿฐํƒ€์ž„/๋ฐฐํฌ JAR์—์„œ๋Š” ์ œ์™ธ
  compileOnly 'org.projectlombok:lombok'
  annotationProcessor 'org.projectlombok:lombok' // ์–ด๋…ธํ…Œ์ด์…˜ ํ”„๋กœ์„ธ์„œ ๋“ฑ๋ก

  // 4. runtimeOnly: ์ปดํŒŒ์ผ ์‹œ์ ์—๋Š” ๋ถˆํ•„์š”ํ•˜๊ณ  ๋Ÿฐํƒ€์ž„์—๋งŒ ๋™์  ๋กœ๋“œ (DB ๋“œ๋ผ์ด๋ฒ„ ๋“ฑ)
  runtimeOnly 'com.mysql:mysql-connector-j'
  runtimeOnly 'com.h2database:h2'

  // 5. testImplementation: ํ…Œ์ŠคํŠธ ์ฝ”๋“œ(src/test) ์ปดํŒŒ์ผ ๋ฐ ์‹คํ–‰ ์‹œ์—๋งŒ ์‚ฌ์šฉ
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
  testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
}

3. Kotlin DSL vs Groovy DSL ๋ฌธ๋ฒ• ๋น„๊ต

// ==================== Kotlin DSL (build.gradle.kts) ====================
plugins {
    java
    id("org.springframework.boot") version "4.1.1"
    id("io.spring.dependency-management") version "1.1.7"
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(25))
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    testImplementation(kotlin("test"))
}
// ==================== Groovy DSL (build.gradle) ====================
plugins {
    id 'java'
    id 'org.springframework.boot' version '4.1.1'
    id 'io.spring.dependency-management' version '1.1.7'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(25)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
}

4. ์˜์กด์„ฑ ๋ถ„์„ & ์ถฉ๋Œ ํ•ด๊ฒฐ (Dependency Insight)

# 1. ํ”„๋กœ์ ํŠธ ์ „์ฒด ์˜์กด์„ฑ ํŠธ๋ฆฌ ์ถœ๋ ฅ
./gradlew dependencies

# 2. ํŠน์ • ๋นŒ๋“œ ๊ตฌ์„ฑ์˜ ์˜์กด์„ฑ๋งŒ ํ•„ํ„ฐ๋งํ•˜์—ฌ ์ถœ๋ ฅ
./gradlew dependencies --configuration compileClasspath
./gradlew dependencies --configuration runtimeClasspath

# 3. ํŠน์ • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์™œ ํฌํ•จ๋˜์—ˆ๋Š”์ง€, ์ถฉ๋Œ ๋ฐ ๋ฒ„์ „ ์„ ํƒ ๊ฒฝ๋กœ ์ถ”์ 
./gradlew dependencyInsight --dependency log4j-core
./gradlew dependencyInsight --dependency jackson-databind --configuration compileClasspath
// 4. ํŠน์ • ์ „์ด ์˜์กด์„ฑ(Transitive Dependency) ๊ฐ•์ œ ์ œ์™ธ(Exclude)
dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web') {
        // ๋‚ด์žฅ Tomcat์„ ์ œ์™ธํ•˜๊ณ  ๋‹ค๋ฅธ WAS(Undertow ๋“ฑ)๋ฅผ ์“ธ ๋•Œ
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
}

5. ํƒœ์Šคํฌ(Task) ๊ด€๋ฆฌ & ์ปค์Šคํ…€ ํƒœ์Šคํฌ ์ž‘์„ฑ

# ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ํƒœ์Šคํฌ ๋ชฉ๋ก ๋ฐ ์„ค๋ช… ํ™•์ธ
./gradlew tasks
./gradlew tasks --all          # ํ•˜์œ„ ์„ธ๋ถ€ ํƒœ์Šคํฌ๊นŒ์ง€ ๋ชจ๋‘ ๋‚˜์—ด
./gradlew help --task build    # ํŠน์ • ํƒœ์Šคํฌ ์ƒ์„ธ ๋„์›€๋ง
// Kotlin DSL (build.gradle.kts) ์ปค์Šคํ…€ ํƒœ์Šคํฌ ๋“ฑ๋ก
tasks.register("printProjectInfo") {
    group = "custom"
    description = "ํ”„๋กœ์ ํŠธ ๊ธฐ๋ณธ ๋ฉ”ํƒ€์ •๋ณด๋ฅผ ์ฝ˜์†”์— ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค."
    doLast {
        println("ํ”„๋กœ์ ํŠธ ์ด๋ฆ„: ${project.name}")
        println("ํ˜„์žฌ ๋ฒ„์ „: ${project.version}")
    }
}

// ํƒœ์Šคํฌ ์˜์กด ๊ด€๊ณ„ ์ง€์ • (A ์‹คํ–‰ ์ „ B ๋ฐ˜๋“œ์‹œ ์„ ํ–‰)
tasks.named("build") {
    dependsOn("printProjectInfo")
}

6. ํ…Œ์ŠคํŠธ(Test) ์‹คํ–‰ & ๋ฆฌํฌํŠธ

# 1. ๋ชจ๋“  ํ…Œ์ŠคํŠธ ์‹คํ–‰
./gradlew test

# 2. ํŠน์ • ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ๋˜๋Š” ๋ฉ”์„œ๋“œ๋งŒ ์ง€์ • ์‹คํ–‰
./gradlew test --tests UserServiceTest
./gradlew test --tests UserServiceTest.findUserById_Success
./gradlew test --tests *ServiceTest      # ์™€์ผ๋“œ์นด๋“œ ํŒจํ„ด ๋งค์นญ

# 3. ํ…Œ์ŠคํŠธ ์‹คํŒจ ์‹œ ๋‚˜๋จธ์ง€ ํ…Œ์ŠคํŠธ ์ฆ‰์‹œ ์ค‘๋‹จ
./gradlew test --fail-fast

# 4. ํ…Œ์ŠคํŠธ ์„ฑ๊ณต ์—ฌ๋ถ€์™€ ์ƒ๊ด€์—†์ด ๋ฌด์กฐ๊ฑด ์žฌ์‹คํ–‰ (์บ์‹œ ๋ฌด์‹œ)
./gradlew test --rerun-tasks
// JUnit 5 (Jupiter) ํ”Œ๋žซํผ ํ™œ์„ฑํ™” ๋ฐ ํ…Œ์ŠคํŠธ ๋กœ๊น… ์„ค์ •
tasks.named('test') {
    useJUnitPlatform()
    testLogging {
        events 'passed', 'skipped', 'failed'
        showStandardStreams = true // System.out ์ถœ๋ ฅ ์ฝ˜์†” ํ‘œ์‹œ
    }
}
// ํ…Œ์ŠคํŠธ ์™„๋ฃŒ ํ›„ HTML ๋ฆฌํฌํŠธ ์ƒ์„ฑ ์œ„์น˜:
// build/reports/tests/test/index.html

7. JAR ํŒจํ‚ค์ง• & ์•„ํ‹ฐํŒฉํŠธ ๋นŒ๋“œ

// Spring Boot ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ Fat-JAR vs ์ˆœ์ˆ˜ JAR ์ œ์–ด
bootJar {
    archiveBaseName = 'my-service'       // ์ƒ์„ฑ๋  ํŒŒ์ผ๋ช…: my-service-1.0.0.jar
    archiveVersion = '1.0.0'
}

// ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์•„๋‹Œ ์ผ๋ฐ˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ฒฝ์šฐ plain jar ๋น„ํ™œ์„ฑํ™” ๊ถŒ์žฅ
jar {
    enabled = false                      // my-service-1.0.0-plain.jar ์ƒ์„ฑ ๋ฐฉ์ง€
}

// ์†Œ์Šค ์ฝ”๋“œ ๋ฐ javadoc JAR ํ•จ๊ป˜ ์ƒ์„ฑํ•˜๊ธฐ
java {
    withSourcesJar()
    withJavadocJar()
}

8. ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ํ”„๋กœ์ ํŠธ ๊ตฌ์„ฑ (Multi-Project)

// settings.gradle (๋ฃจํŠธ ์„ค์ • ํŒŒ์ผ์—์„œ ํ•˜์œ„ ๋ชจ๋“ˆ ๋“ฑ๋ก)
rootProject.name = 'ecommerce-platform'
include 'core-domain'
include 'api-server'
include 'admin-server'
include 'batch-worker'
// ๋ฃจํŠธ build.gradle (๋ชจ๋“  ์„œ๋ธŒ ๋ชจ๋“ˆ ๊ณตํ†ต ์„ค์ •)
subprojects {
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'

    repositories {
        mavenCentral()
    }

    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
    }
}

// ์„œ๋ธŒ ๋ชจ๋“ˆ(api-server/build.gradle)์—์„œ ๋‹ค๋ฅธ ๋ชจ๋“ˆ ์ฐธ์กฐ
dependencies {
    implementation project(':core-domain') // ๋กœ์ปฌ ๋ชจ๋“ˆ ์˜์กด์„ฑ ์ฃผ์ž…
}

9. ๋นŒ๋“œ ์†๋„ ์ตœ์ ํ™” (gradle.properties)

# ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๋˜๋Š” ~/.gradle/gradle.properties ์— ์ถ”๊ฐ€

# 1. JVM ํž™ ๋ฉ”๋ชจ๋ฆฌ ๋ฐ Metaspace ํ™•์žฅ
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError

# 2. ๋ฉ€ํ‹ฐ์ฝ”์–ด CPU ๋ณ‘๋ ฌ ํƒœ์Šคํฌ ์‹คํ–‰ (๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ์‹œ ํ•„์ˆ˜)
org.gradle.parallel=true

# 3. ๋นŒ๋“œ ์บ์‹œ ํ™œ์„ฑํ™” (๋ณ€๊ฒฝ๋˜์ง€ ์•Š์€ ํƒœ์Šคํฌ ๊ฒฐ๊ณผ ์žฌ์‚ฌ์šฉ)
org.gradle.caching=true

# 4. ํŒŒ์ผ ์‹œ์Šคํ…œ ๊ฐ์‹œ ๊ธฐ๋Šฅ ํ™œ์„ฑํ™” (ํŒŒ์ผ ๋ณ€๊ฒฝ ์ถ”์  ์‹œ๊ฐ„ ๋‹จ์ถ•)
org.gradle.vfs.watch=true

# 5. ์„ค์ • ์บ์‹œ ํ™œ์„ฑํ™” (Gradle 8+ ๋นŒ๋“œ ์‹œ์ž‘ ์‹œ๊ฐ„ ํš๊ธฐ์  ๋‹จ์ถ•)
org.gradle.configuration-cache=true

10. ์‹ค๋ฌด ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ… & ๊ฟ€ํŒ (Gotchas)

# 1. Gradle Wrapper ์ž์ฒด ๋ฒ„์ „ ์—…๊ทธ๋ ˆ์ด๋“œ (์ตœ์‹  8.x ์ ์šฉ)
./gradlew wrapper --gradle-version 8.7 --distribution-type bin

# 2. "Could not find or load main class org.gradle.wrapper.GradleWrapperMain"
# -> gradlew ์‹คํ–‰ ์Šคํฌ๋ฆฝํŠธ๋งŒ ์žˆ๊ณ  gradle/wrapper/gradle-wrapper.jar ํŒŒ์ผ์ด gitignore ๋“ฑ์œผ๋กœ ์œ ์‹ค๋œ ๊ฒฝ์šฐ
gradle wrapper # ์‹œ์Šคํ…œ์— ์„ค์น˜๋œ ๋กœ์ปฌ gradle๋กœ wrapper ๋ณต๊ตฌ

# 3. Windows ํ™˜๊ฒฝ gradlew ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ (Linux/Mac/CI)
git update-index --chmod=+x gradlew

# 4. ๊ผฌ์ธ ์˜์กด์„ฑ ๋กœ์ปฌ ์บ์‹œ ๋””๋ ‰ํ† ๋ฆฌ ์ˆ˜๋™ ์‚ญ์ œ (์ตœํ›„์˜ ์ˆ˜๋‹จ)
# Mac/Linux: rm -rf ~/.gradle/caches/
# Windows: Remove-Item -Recurse -Force ~/.gradle/caches/
๐Ÿ’ฌ

์˜๊ฒฌ ๋ฐ ์งˆ๋ฌธ

0
0 / 1500