Intro

Maven 의 철학은 Convention Over Configuration 이다.


ant 를 쓸때는 source는 어느 폴더에 있는지 build 한 산출물은 어디에 위치해야 하는지 각종 property와 xml 은 어디에 있고 어떻게 묶어야 하는지를 일일이 지정해 줘야 했지만 maven은 대부분의 것들을 관례(Convention)에 의거해 처리하고 있다.


관례를 따르면 편한 점은 관례를 알고 있다면 세세한 설정을 다시 할 필요가 없으므로 설정이 거의 없거나 매우 단순해 진다는 점이다.

하지만 관례를 모르면 사용이 불가능하다는 단점이 있지만 java build 는 몇가지 관례만 알면 간단하게 maven 으로 build 환경을 구성할 수 있다.


예로 java 소스는 ${basedir}/src/main/java 위치하고 xml이나 property등은 ${basedir}/src/main/resources 에 있다고 가정하고 test 코드는 ${basedir}/src/main/test 에 있고 기본 산출물은 jar 라고 가정하고 있다.


실제로 jar 파일을 만드는 프로젝트이며 관례에 따른다면 다음 pom.xml 처럼 groupId, artifactId, version 등의 정보만 주어도 충분하다.

<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>com.example.app</groupId>
  <artifactId>testapp</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</project>
HTML/XML


하지만 여러 하위 프로젝트로 나눠어져 있고 여러개의 profile 과 parent-pom 등으로 구성된 복잡한  maven 프로젝트라면 현재의 프로젝트의 구성이 어떻게 되어 있는지 사용하는 어떤 프로파일이 사용되는지등의 구체적인 정보를 확인해 봐야 할 필요가 있다.


이럴때 help plugin 은 유용하게 사용될 수 있다.

Goal Overview

Help Plugin 은 총 8개의 goal 을 갖고 있다.


help:active-profiles

현재 프로젝트에서 활성화된 프로파일의 목록을 출력한다.


help:all-profiles

현재 프로젝트에서 활성화된 프로파일의 목록을 출력한다.


help:describe 

Maven Plugin 이나 Mojo (Maven plain Old Java Object)의 attribute 에 대해서 기술해 준다.

예로 deploy phrase의 정보를 보려면 다음과 같이 하면 된다.


 mvn help:describe  -Dcmd=deploy

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testapp 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ testapp ---
[INFO] 'deploy' is a phase corresponding to this plugin:
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy

It is a part of the lifecycle for the POM packaging 'jar'. This lifecycle includes the following phases:
* validate: Not defined
* initialize: Not defined
* generate-sources: Not defined
* process-sources: Not defined
* generate-resources: Not defined
* process-resources: org.apache.maven.plugins:maven-resources-plugin:2.5:resources
* compile: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
* process-classes: Not defined
* generate-test-sources: Not defined
* process-test-sources: Not defined
* generate-test-resources: Not defined
* process-test-resources: org.apache.maven.plugins:maven-resources-plugin:2.5:testResources
* test-compile: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile
* process-test-classes: Not defined
* test: org.apache.maven.plugins:maven-surefire-plugin:2.10:test
* prepare-package: Not defined
* package: org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar
* pre-integration-test: Not defined
* integration-test: Not defined
* post-integration-test: Not defined
* verify: Not defined
* install: org.apache.maven.plugins:maven-install-plugin:2.3.1:install
* deploy: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.098s
[INFO] Finished at: Wed Jul 17 13:24:36 KST 2013
[INFO] Final Memory: 6M/238M
[INFO] ------------------------------------------------------------------------


특정 plugin 에 대한 정보를 볼 경우는 -Dplugin 옵션을 주면 되고 되고 groupId 로 정보를 볼 경우는 -DgroupId 옵션을 줄수 있다.

plugin 정보 보기

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-help-plugin

groupId로 정보 보기

mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-help-plugin

help plugin 에 대한 자세한 내용은 "mvn help:help -Ddetail=true"  로 확인할 수 있다.

help:effective-pom  

현재 build와 profile 설정으로 생성되는 최종 POM 파일을 확인할 수 있다. 현재 maven build 가 참고하는 빌드 내용을 봐야 할 필요가 있을 경우 참고하자.


help:effective-settings 

maven은 개인별 설정이 필요한 부분은 ${HOME}/.m2/settings.xml 에 기술할 수 있다. effective-settings 는 현재 개인별 settings 의 내용을 표시해 준다.


help:evaluate

interactive mode에서 maven 설정을 확인할 수 있게 해준다. 해당 goal 을 실행하면 다음과 같은 shell prompt 가 뜬다.

[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:

값을 알고 싶은 maven expression 을 입력하면 결과를 보여주며 0 을 입력하면 종료된다.

예로 ${project.artifactId} 를 입력하면 현재 프로젝트의 artifactId 를 출력한다.

이 goal 은 그리 유용해 보이지는 않는다.


help:expressions

displays the supported Plugin expressions used by Maven.


help:system

System properties 와 environment variables 등을 출력한다. JDK 버전 및 OS 의 shell 변수등의 정보를 출력해 준다.

참고자료