2022년 4월 27일 수요일

gradle7 멀티프로파일 오류

새로 프로젝트를 만들고 프로파일별로 리소스폴더 만들고 빌드하니 다음과 같은 에러가 발생했다. 


Execution failed for task ':processResources'.

> Entry application.properties is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.4/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.


* Try:

> Run with --stacktrace option to get the stack trace.

> Run with --info or --debug option to get more log output.

> Run with --scan to get full insights.


이전 프로젝트는 gradle6 이었는데 7부터 바뀌었나 보다.
구글링 해보니 다음과 같은 해결책을 찾을 수 있었다.
tasks {
processResources { duplicatesStrategy = DuplicatesStrategy.INCLUDE }
}
INCLUDE로 정하면 소스셋에서 정한 디렉토리 순서에 따라서 마지막 파일로 덮어 쓴다.
sourceSets {
main {
resources {
srcDirs "src/main/resources", "src/main/resources-${profile}"
}

}
}