[Gradle] --project-prop 옵션으로 특정 파일 제외하여 빌드하기
웹/Java2025. 3. 7. 16:44
이번에 Swagger를 활용해 API 문서를 작성하면서,
개발 서버에서만 쓰이는 내부용 컨트롤러에 아예 접근할 수 없도록 처리할 필요가 있었다.
@Hidden, @Profile 등 여러 방법을 찾아 보다 gradle로 아예 파일 자체를 빼고 빌드하기로 했다.
https://docs.gradle.org/current/userguide/command_line_interface.html#sec:environment_options
Command-Line Interface Reference
Gradle provides several built-in tasks which show particular details of your build. This can be useful for understanding your build’s structure and dependencies, as well as debugging problems. Running the projects task gives you a list of the subprojects
docs.gradle.org
gradle로 스프링 부트 프로젝트를 빌드할 때, -p 라는 옵션으로 시스템 프로퍼티를 설정할 수 있는데,
./gradlew clean build --no-scan --build-cache -x test -P{property}
이렇게 설정하고 나서 gradle.build에서 project.hasProperty('property값') 으로 조건을 만들어 제외할 파일을 지정할 수 있다.
// 제외할 폴더 지정 (빌드시 -Pproperty 사용한 경우 적용됨)
jar {
if (project.hasProperty('property')) {
sourceSets {
main {
java {
exclude "**/제외할 폴더 또는 파일 경로"
}
}
}
}
}
그렇게 빌드하고 나서 jar 파일로 프로젝트를 실행시키면 해당 파일은 깔끔하게 제외된다!
'웹 > Java' 카테고리의 다른 글
@Conditional (0) | 2025.03.21 |
---|---|
프로파일별로 다른 파일이 실행되도록 세팅하기 (0) | 2024.08.02 |
*.properties 내 값 enum 클래스로 받아 관리하기 (0) | 2024.07.26 |
댓글()