Maven Profile

2020. 3. 31. 18:13빌드 도구/Maven

Maven Profile란

Maven Profile란 특정 Build 환경에 맞춘 리소스의 재배치 및 환경에 대한 옵션 설정들을 실행할 수 있게 하는 기능입니다. 일반적으로 빌드 환경을 개발 / 알파 / 스테이징 / 운영 시스템 단위로 구분한다고 했을 때, 각 단계에서 필요로 하는 설정 정보나 리소스 파일들을 배치시키는 역할을 합니다.

Maven Profile 사용법

<profiles>
   <profile>
       <id>local</id>
       <properties>
           <maven.test.skip>false</maven.test.skip>
           <deploy.phase>local</deploy.phase>
       </properties>
       <activation>
           <activeByDefault>true</activeByDefault>
       </activation>
   </profile>
   <profile>
       <id>dev</id>
       <properties>
           <maven.test.skip>false</maven.test.skip>
           <deploy.phase>dev</deploy.phase>
           <outputDirectory.war>../../deploy</outputDirectory.war>
       </properties>
   </profile>
   <profile>
       <id>alpha</id>
       <properties>
           <maven.test.skip>true</maven.test.skip>
           <deploy.phase>alpha</deploy.phase>
           <outputDirectory.war>../../deploy</outputDirectory.war>
       </properties>
   </profile>
</profiles>
  • Id: prlfile Id
  • Maven.test.skip: maven test를 skip할 것인지의 여부
  • Deployee.phase: 환경별 phase 정보를 구분하여, 리소스 관리를 하도록 함
  • Activation: 활성화 정보 여부, 위에서는 activeProfiles 설정이 없을 경우 local을 defaultProfile로 설정

Deployee.phase는 빌드 시에 다음과 같이 사용할 수 있습니다.

<build>
   <sourceDirectory>src/main/java</sourceDirectory>
   <testSourceDirectory>src/test/java</testSourceDirectory>
   <outputDirectory>${project.basedir}/target/classes</outputDirectory>
   <resources>
       <resource>
           <directory>src/main/resources</directory>
           <filtering>true</filtering>
       </resource>
       <resource>
           <directory>src/main/resources-${deploy.phase}/</directory>
           <filtering>true</filtering>
       </resource>
   </resources>
</build>
  • Src/main/resources: 리소스 중 공통적인 내용들은 위의 경로에서 관리하도록 합니다.
  • Src/main/resources-${deploy.phase}: 리소스 중 배포 환경 별 구분해야 하는 내용들은 deploy.phase로 구분하여 관리합니다.
728x90

'빌드 도구 > Maven' 카테고리의 다른 글

Maven  (0) 2022.02.27
maven-war-plugin  (0) 2020.04.04
Maven Scope  (0) 2020.04.01