Gradle 8.10 버전에서 테스트하였음
상황
스프링 부트를 사용중이며 yml 파일로 설정을 관리함
서버 환경별로 환경에 맞는 yml파일만 배포되어야 함
로컬, 개발, 운영에 해당하는 yml파일이 존재
설정
1. application.yml
spring:
config:
import:
- "classpath:yml/${spring.profiles.active}/application-${spring.profiles.active}-interface.yml
2. build.gradle
def activeProfile = project.hasProperty('profile') ? project.getProperty('profile') : 'local'
tasks.named("processResources") {
filesMatching("yml/**") { file ->
def parentDir = file.file.parentFile.name
if(parentDir == activeProfile) {
include()
println "include: ${file.path}"
} else {
exclude()
println "exclude: ${file.path}"
}
doLast {
println "building with profile: ${activeProfile}"
}
}
3. 빌드명령어
gradlew build -Pprofile=[local|dev|prd]
'웹개발 > 스프링 · 자바 · 코틀린' 카테고리의 다른 글
[스프링] 트랜잭션 롤백 (0) | 2025.02.28 |
---|---|
세션 타임아웃 처리 - polling 이 있는 경우 (0) | 2025.02.28 |
[java] enum을 String[]으로 변환하기 (0) | 2024.05.31 |
[java] swing 시작하기 (0) | 2024.05.31 |
private final (0) | 2024.01.22 |