Create a Spring Boot project with Kotlin | Kotlin
kotlinlang.org
코틀린 공식 문서에 나와있는 코프링 프로젝트의 예제를 작성하다가, gradle 빌드 스크립트를 groovy 에서 kotlin으로 처음 사용해 보았습니다.
기존에 Java와 gradle-groovy를 사용할 때와 몇가지 추가된 설정들이 있어 주석과 함께 기록을 남겨봅니다.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile // For `KotlinCompile` task below
plugins {
id("org.springframework.boot") version "3.1.3"
id("io.spring.dependency-management") version "1.1.3"
kotlin("jvm") version "1.9.10" // The version of Kotlin to use
// Spring Framework 기능과 호환되도록 Kotlin 클래스에 open 수정자를 추가하는 Kotlin Spring 컴파일러 플러그인
kotlin("plugin.spring") version "1.9.10"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("org.springframework.boot:spring-boot-starter-web")
// 이 모듈은 Kotlin 클래스 및 데이터 클래스의 직렬화 및 역직렬화에 대한 지원을 추가합니다.
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") // Jackson extensions for Kotlin for working with JSON
// 코틀린 리플렉션 라이브러리
implementation("org.jetbrains.kotlin:kotlin-reflect") // Kotlin reflection library, required for working with Spring
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
// 여기에서 컴파일러에 추가 인수를 추가하여 다양한 언어 기능을 활성화하거나 비활성화할 수 있습니다.
tasks.withType<KotlinCompile> { // Settings for `KotlinCompile` tasks
kotlinOptions { // Kotlin compiler options
freeCompilerArgs += "-Xjsr305=strict" // `-Xjsr305=strict` enables the strict mode for JSR-305 annotations
jvmTarget = "17" // This option specifies the target version of the generated JVM bytecode
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
이후에 멀티모듈도 적용해보면서 기존과 어떤 차이점이 있는지 확인해봐야겠습니다.