개요

메이븐은 프로파일 기능을 이용하여 조건에 따라서 JDK 를 다른 버전으로 build 하거나 특정 환경에 맞게 packaging 등을 할수 있음

 

 

사용

Types of profile

  • Per Project
    • Defined in the POM itself (pom.xml).
  • Per User
    • Defined in the Maven-settings (%USER_HOME%/.m2/settings.xml).
  • Global
    • Defined in the global Maven-settings (%M2_HOME%/conf/settings.xml).
  • Profile descriptor
    • a descriptor located in project basedir (profiles.xml) (unsupported in Maven 3.0: see Maven 3 compatibility notes)

 

profile 설정

다음과 같은 방법을 통해 profile 설정이 가능

  1. 실행시 -P 커맨드 옵션을 통해 전달 (Ex: mvn mygoal -P profile-1,profile-2)
  2. settings.xml 에 기술

 

profile activation

특정 profile activation 은 activeProfiles section 에서 설정 가능

<settings>
  ...
  <activeProfiles>
    <activeProfile>profile-1</activeProfile>
  </activeProfiles>
  ...
</settings>
CODE


activation section 은 특정 조건일때 실행될 profile 을 설정

아래의 pom.xml 은 jdk 가 1.6 일때 jdk16 profile 을 실행

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sonatype.mavenbook</groupId>
    <artifactId>simple</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>simple</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>jdk16</id>
            <activation> (1)
                    <jdk>1.6</jdk>
            </activation>
            <modules> (2)
                    <module>simple-script</module>
            </modules>
        </profile>
    </profiles>
</project>
XML

 

See Also

 

Ref