일반 적으로 application-${profile}.properties 형태로 사용하여 실행옵션에 active profile로 사용할 properties를 지정해줍니다. 이와 같은 방법에는 아래와 같은 단점이 있습니다.
// build 시 profile 옵션이 빠졌을시 자동으로 local로 세팅 -> 해당 ide에서 따로 세팅할필요가없다.
ext.profile = (!project.hasProperty('profile') || !profile) ? 'local' : profile
//resources-* 를 전체 제외 시키고 필요한 resources-${profile} 만 빌드에 포함시킨다.
sourceSets{
main{
resources {
srcDirs "src/main/resources/resources-${profile}"
exclude "resources-*"
}
}
}
#개발환경에 상관없는 공통 프로퍼티
spring.profiles.include=core
#active profile
spring.profiles.active=local
빌드된 jar 파일의 압축을 풀었을때 위와 같이 해당 properties 파일만 들어간것을 확인할 수 있습니다.