by-nc-sa     개발자, DBA가 함께 만들어가는 구루비 지식창고!

유용한 Maven Plugin 소개 및 예제




유용한 Maven Plugin 소개 및 예제

1. maven-antrun-plugin

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>
    

문서정보

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.