Maven - POM
project dependencies
plugins
goals
build profiles
project version
developers
mailing list
Example POM
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
All POM files require the project element and three mandatory fields: groupId, artifactId,version. (모든 POM파일은 프로젝트 요소와 세개의 필수적인 필드가 필요하다.)
Projects notation in repository is groupId:artifactId:version. (저장소내 프로젝트 명은 groupId:artifcatID:version이다.)
Root element of POM.xml is project and it has three major sub-nodes : (POM.xml의 root 요소는 프로젝트이고 이것은 세개의 주요 하위노드를 갖는다.)
Node | Description |
---|---|
groupId | This is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects. (프로젝트 그룹의 ID. 조직 또는 프로젝트에서 일반적으로 유일하다. 예를 들면 banking group com.company.bank는 프로젝트와 관련된 모든 bank를 갖는다.) |
artifactId | This is an Id of the project.This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository. (프로젝트 ID. 일반적으로 프로젝트의 이름이다. 예를 들면, consumer-banking. groupID에 함께 artifactID는 저장소에서 artifact의 위치를 정의한다.) |
version | This is the version of the project.Along with the groupId, It is used within an artifact's repository to separate versions from each other. For example: (프로젝트 버전. groupID와 함께 각각 분리된 버전으로 artifact의 저장소내에서 사용된다. 예를 들면 아래와 같다.) com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1. |
모든 POM은 부모(명시적으로 선언되어지는 것과 상관없이)로부터 상속한다. 이 base POM은 'Super POM'으로 알려져 있고 기본적으로 상속되어진 값을 포함한다.
Maven은 관련있는 목표(goal)을 실행하기 위해 효과적인 pom(super pom에서의 설정 + 프로젝트 설정)을 사용한다. 비록 설정이 쉽게 덮어써질 수 있긴 하지만이는 개발자가 pom.xml에 최소한의 설정을 기술하는 것을 돕는다.
(** 아래 예제는 원문을 그대로 옮긴다. eclipse Mar.1인 현재 개발 환경에서는 maven project를 생성하면 끝이기 때문이다.)
Super pom의 기본설정을 찾는 가장 쉬운 방법은 다음 명령을 실행하는 것이다. : mvn help:effective-pom
임의의 디렉토리에서 pom.xml을 생성하라. 위에 언급된 예제 pom의 컨텐트를 사용하라.
아래 예제에서, C:\MVN\project 폴더에 pom.xml을 생성한다.
콘솔을 열고 pom.xml을 포함하는 폴더로 간 후 아래 mvn명령을 실행한다.
C:\MVN\project>mvn help:effective-pom
Maven은 처리를 시작하고 effective-pom을 출력할 것이다.
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'help'. [INFO] ------------------------------------------------------------------------ [INFO] Building Unnamed - com.companyname.project-group:project-name:jar:1.0 [INFO] task-segment: [help:effective-pom] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] [help:effective-pom {execution: default-cli}] [INFO] ..... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Thu Jul 05 11:41:51 IST 2012 [INFO] Final Memory: 6M/15M [INFO] ------------------------------------------------------------------------
결과로 콘솔에 출력된 effective POM, 상속이후, 삽입, 그리고 프로파일이 적용되었다.
<!-- ====================================================================== --> <!-- --> <!-- Generated by Maven Help Plugin on 2015-09-26T07:51:19 --> <!-- See: http://maven.apache.org/plugins/maven-help-plugin/ --> <!-- --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- --> <!-- Effective POM for project --> <!-- 'com.companyname.project-group:project:jar:1.0' --> <!-- --> <!-- ====================================================================== --> <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 h ttp://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </pluginRepository> </pluginRepositories> <build> <sourceDirectory>C:\MVN\project\src\main\java</sourceDirectory> <scriptSourceDirectory>C:\MVN\project\src\main\scripts</scriptSourceDirector y> <testSourceDirectory>C:\MVN\project\src\test\java</testSourceDirectory> <outputDirectory>C:\MVN\project\target\classes</outputDirectory> <testOutputDirectory>C:\MVN\project\target\test-classes</testOutputDirectory > <resources> <resource> <directory>C:\MVN\project\src\main\resources</directory> </resource> </resources> <testResources> <testResource> <directory>C:\MVN\project\src\test\resources</directory> </testResource> </testResources> <directory>C:\MVN\project\target</directory> <finalName>project-1.0</finalName> <pluginManagement> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>default-clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>default-install</id> <phase>install</phase> <goals> <goal>install</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>default-resources</id> <phase>process-resources</phase> <goals> <goal>resources</goal> </goals> </execution> <execution> <id>default-testResources</id> <phase>process-test-resources</phase> <goals> <goal>testResources</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <executions> <execution> <id>default-test</id> <phase>test</phase> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <executions> <execution> <id>default-testCompile</id> <phase>test-compile</phase> <goals> <goal>testCompile</goal> </goals> </execution> <execution> <id>default-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>default-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <executions> <execution> <id>default-site</id> <phase>site</phase> <goals> <goal>site</goal> </goals> <configuration> <outputDirectory>C:\MVN\project\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </execution> <execution> <id>default-deploy</id> <phase>site-deploy</phase> <goals> <goal>deploy</goal> </goals> <configuration> <outputDirectory>C:\MVN\project\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </execution> </executions> <configuration> <outputDirectory>C:\MVN\project\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </plugin> </plugins> </build> <reporting> <outputDirectory>C:\MVN\project\target\site</outputDirectory> </reporting> </project>
위의 pom.xml에서 Maven이 희망하는 목표(goal)을 실행하는 동안 사용할 프로젝트 소스 폴더 구조, 출력 디렉토리, 필요한 plug-in, 저장소, 레포팅 디렉토리를 볼수 있다.
Maen pom.xml은 수동으로 작성하는 것을 요구하지 않는다.
Maven은 프로젝트 구조와 pom.xml을 생성하기 위한 프로젝트를 생성하는 다양한 원형을 제공한다.