gradle init | 프로젝트 초기화 |
gradle build | 프로젝트 빌드 |
gradle clean | 빌드 정리 |
gradle test | 테스트 실행 |
gradle tasks | 태스크 목록 |
gradle dependencies | 의존성 표시 |
gradle bootRun | Spring Boot 실행 |
gradle --refresh-dependencies | 의존성 새로고침 |
./gradlew build | 래퍼 사용 |
plugins {
java
application
id("org.springframework.boot") version "3.2.0"
}
group = "com.example"
version = "1.0.0"
java {
sourceCompatibility = JavaVersion.VERSION_17
}
application {
mainClass.set("com.example.Main")
}
repositories {
mavenCentral()
} dependencies {
// Implementation
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.google.guava:guava:32.1.3-jre")
// Compile only
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
// Test
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
} plugins {
id 'java'
id 'application'
}
group = 'com.example'
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}
test {
useJUnitPlatform()
} tasks.register("hello") {
group = "custom"
description = "Prints hello"
doLast {
println("Hello, Gradle!")
}
}
tasks.register<Copy>("copyDocs") {
from("src/docs")
into("build/docs")
}
tasks.register<Zip>("zipDist") {
from("build/libs")
archiveFileName.set("dist.zip")
destinationDirectory.set(file("build"))
} tasks.named("build") {
dependsOn("hello")
finalizedBy("copyDocs")
}
tasks.register("fullBuild") {
dependsOn("clean", "build", "test")
}
// Configure existing task
tasks.test {
useJUnitPlatform()
maxParallelForks = 4
testLogging {
events("passed", "skipped", "failed")
}
} rootProject.name = "my-project"
include("app")
include("lib")
include("common")
// Or with custom paths
include("modules:api")
include("modules:core") // In app/build.gradle.kts
dependencies {
implementation(project(":lib"))
implementation(project(":common"))
}
// Root build.gradle.kts - shared config
subprojects {
apply(plugin = "java")
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
}
} plugins {
`maven-publish`
signing
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name.set("My Library")
description.set("A library")
url.set("https://github.com/user/repo")
}
}
}
repositories {
maven {
url = uri("https://repo.example.com")
credentials {
username = project.findProperty("repoUser") as String?
password = project.findProperty("repoPass") as String?
}
}
}
}