- 이 문서는 구루비에서 작성하였습니다.
- 이 문서를 다른 블로그나 홈페이지에 게재하실 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 출처 : http://wiki.gurubee.net/pages/viewpage.action?pageId=26740779&
- 구루비 지식창고의 모든 문서는 크리에이티브 커먼즈의 저작자표시-비영리-동일조건변경허락(BY-NC-SA) 라이선스에 따라 자유롭게 사용할 수 있습니다.
유용한 Maven Plugin 소개 및 예제
1. maven-antrun-plugin
- http://maven.apache.org/plugins/maven-antrun-plugin/
- This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM!
- maven-antrun-plugin 를 사용하면 copy, delete 작업 등을 쉽게 할 수 있다.
1.1 clean 예제
- mvn clean 실행
- dependency library 파일을 삭제 한다 .
pom.xml
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>delete-dependency-library</id>
<phase>clean</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
<delete><fileset dir="${basedir}/webapps/WEB-INF/lib" /></delete>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
1.2 delete 및 copy 예제
- mvn compile 시 delete및 copy를 실행하는 예
pom.xml
<build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <delete file="${project.build.outputDirectory}/log4j.xml"/> <copy file="src/main/resources-local/log4j-local.xml" tofile="${project.build.outputDirectory}/log4j.xml"/> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build>
1.3 js, css파일 버전정보 적용예
- jsp 파일의 js, css 파일정보에 버전정보 적용하는 예이다.
- buildVersion을 프로젝트 버전으로 치환한다.
- .jsp 파일 내용
.jsp
... <link rel="stylesheet" type="text/css" href="http://www.gurubee.net/mashup/yahoo/css/skin.css?@buildVersion@" /> <link rel="stylesheet" type="text/css" href="http://www.gurubee.net/mashup/yahoo/css/YUIEditor-min.css?@buildVersion@" /> <script type="text/javascript" src="http://www.gurubee.net/common/js/Common.js?@buildVersion@"></script> ...
- pom.xml 내용
pom.xml
<modelVersion>4.0.0</modelVersion> <groupId>com.gurubee.service</groupId> <artifactId>gurubee-project</artifactId> <packaging>jar</packaging> <version>4.1.0.3</version> <name>gurubee Project</name> <url>http://www.gurubee.net/</url> <profile> <id>release</id> <properties> <env>release</env> </properties> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>set-version-resource-file</id> <phase>generate-sources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo message="##### Setting product version in source code" /> <replace dir="${project.basedir}/webapps/WEB-INF/pages" includes="**/*.jsp" token="@buildVersion@" value="${project.version}" encoding="UTF-8" /> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
1.4 기타 기능
2. yuicompressor-maven-plugin
- http://refresh-sf.com/yui/
- JavaScript, CSS 최적화
- Ant, Maven Plugin 지원
- mvn -Prelease compile yuicompressor:compress war:exploded
- pom.xml 내용
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/maven-v4_0_0.xsd"> ... <build> ... <plugins> ... <!-- yuicompressor:compress --> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>yuicompressor-maven-plugin</artifactId> <version>1.2</version> <configuration> <jswarn>false</jswarn> <sourceDirectory>${project.basedir}/webapps/common</sourceDirectory> <outputDirectory>${project.basedir}/webapps/common</outputDirectory> <encoding>${project.build.sourceEncoding}</encoding> <excludes> <exclude>**/*min.js</exclude> <exclude>**/*min.css</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.properties</exclude> </excludes> </configuration> </plugin> ... </plugins> </build> </project>
문서정보
- 이 문서는 구루비에서 작성하였습니다.
- 이 문서를 다른 블로그나 홈페이지에 게재하실 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 출처 : http://wiki.gurubee.net/pages/viewpage.action?pageId=26740779&
- 구루비 지식창고의 모든 문서는 크리에이티브 커먼즈의 저작자표시-비영리-동일조건변경허락(BY-NC-SA) 라이선스에 따라 자유롭게 사용할 수 있습니다.