Maven - Plug-ins
(원문 위치 : http://www.tutorialspoint.com/maven/maven_plugins.htm )
What are Maven Plugins?
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
mvn [plugin-name]:[goal-name]
mvn compiler:compile
Type | Description |
---|---|
Build plugins | They execute during the build and should be configured in the <build/> element of pom.xml (pom.xml의 <build/>요소에 설정되어져야 하고 build동안 실행한다.) |
Reporting plugins | They execute during the site generation and they should be configured in the <reporting/> element of the pom.xml (pom.xml의 <reporting/>요소에 설정되어지고 사이트 생성동안 실행한다.) |
아래는 몇가지 일반 plugin 목록이다.
Plugin | Description |
---|---|
clean | Clean up target after the build. Deletes the target directory.(build후 target 정리. target디렉토리 삭제.) |
compiler | Compiles Java source files.(자바 소스파일 compile) |
surefile | Run the JUnit unit tests. Creates test reports.(Unit unit test실행. 테스트 리포트 생성) |
jar | Builds a JAR file from the current project.(현재 프로젝트에서 JAR 파일 build) |
war | Builds a WAR file from the current project.(현재 프로젝트에서 WAR파일 build) |
javadoc | Generates Javadoc for the project.(프로젝트를 위한 javadoc 생성) |
antrun | Runs a set of ant tasks from any phase mentioned of the build.(build의 언급된 어떤 단계로부터 ant 작업 set 실행) |
Example
콘솔에 data를 출력하기 위한 예제에서 광범위하게 maven-antrun-plugin을 사용한다. [003] Maven Profiles를 보자. C:\MVN\project폴더에 pom.xml을 생성하는 더 좋은 방법을 이해해 보자.
<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.projectgroup</groupId> <artifactId>project</artifactId> <version>1.0</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.clean</id> <phase>clean</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>clean phase</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
다음으로 콘솔을 열고 pom.xml이 있는 폴더로 가서 아래 mvn명령을 실행한다.
C:\MVN\project>mvn clean
Maven은 처리를 시작하고 clean life cycle의 clean단계를 출력할 것이다.
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------ [INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0 [INFO] task-segment: [post-clean] [INFO] ------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean}] [INFO] [antrun:run {execution: id.clean}] [INFO] Executing tasks [echo] clean phase [INFO] Executed tasks [INFO] ------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Sat Jul 07 13:38:59 IST 2012 [INFO] Final Memory: 4M/44M [INFO] ------------------------------------------------------------------
위 예제는 아래 주요 개념을 나타낸다.
Plugins are specified in pom.xml using plugins element.(Plugin은 plugin 요소를 사용하여 pom.xml에 명시되어진다.)
Each plugin can have multiple goals.(각각의 plugin은 다중의 목표를 가질 수 있다.)
You can define phase from where plugin should starts its processing using its phase element. We've used clean phase.(단계 요소를 사용하여 처리를 시작해야 하는 plugin에서 단계를 정의할 수 있다. clean 단계를 사용했다.)
You can configure tasks to be executed by binding them to goals of plugin. We've bound echo task with run goal of maven-antrun-plugin.(plugin의 목표에 binding하는 것으로 실행되기 위한 작업을 설정할 수 있다. maven-antrun-plugin의 run 목표와 echo 작업을 묶었다.)
That's it, Maven will handle the rest. It will download the plugin if not available in local repository and starts its processing.(끝이다. Maven은 나머지를 제어할 것이다. 로컬 저장소에서 가능하지 않다면 plugin을 다운로드 하고 처리를 시작한다.)