Example: 使用maven plugin定制build

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
   
  <parent>
    <artifactId>RMDirectProject</artifactId>
    <groupId>RMDirect</groupId>
    <version>SNAPSHOT</version>
  </parent>
 
    <name>bbConfigsCommon</name>
    <groupId>bbConfigs</groupId>
    <artifactId>bbConfigsCommon</artifactId>
  <version>SNAPSHOT</version>
  
  <!-- TODO -->
  <!-- put build section to a parent project so that no duplicate script across multiple config projects -->
  <build>
   <resources>
     <resource>
       <directory>src/objectservice</directory>
     </resource>
   </resources>
   <plugins>
      <!-- copy resources in libConfig folder to META-INF/config -->
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <executions>
            <execution>
              <id>copy-resources</id>
              <phase>validate</phase>
              <goals>
                <goal>copy-resources</goal>
              </goals>
              <configuration>
                <outputDirectory>${basedir}/target/classes/META-INF/config</outputDirectory>
                <resources>         
                  <resource>
                    <directory>src/libConfig</directory>
                    <filtering>true</filtering>
                  </resource>
                </resources>             
              </configuration>           
            </execution>
          </executions>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
              <id>create-transform-folder</id>
              <phase>process-sources</phase>
              <goals><goal>run</goal></goals>
              <configuration>
                  <tasks>
                     <mkdir dir="${basedir}/target/transformProducts"/>
                  </tasks>
              </configuration>
            </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
            <!--transfer xml files-->
            <execution>
               <id>transfer-config</id>
               <phase>process-sources</phase>
              <goals>
                <goal>java</goal>
              </goals>
               <configuration>
                  <includeProjectDependencies>false</includeProjectDependencies>
                  <includePluginDependencies>true</includePluginDependencies>
                  <executableDependency>
                    <groupId>AppDev</groupId>
                    <artifactId>configs-helper</artifactId>
                  </executableDependency>
                  <mainClass>com.riskmetrics.appdev.configs.tools.misc.TransformProductConfigs</mainClass>
                  <arguments>
                    <argument>${basedir}/src/configs/product</argument>
                    <argument>${basedir}/target/transformProducts</argument>
                  </arguments>
                </configuration>
             </execution>
            
             <!--build zip files -->
             <execution>
               <id>build-zip-files</id>
               <phase>prepare-package</phase>
              <goals>
                <goal>java</goal>
              </goals>
              <configuration>
                  <includeProjectDependencies>false</includeProjectDependencies>
                  <includePluginDependencies>true</includePluginDependencies>
                  <executableDependency>
                    <groupId>AppDev</groupId>
                    <artifactId>configs-helper</artifactId>
                  </executableDependency>
                  <mainClass>com.riskmetrics.appdev.configs.tools.misc.BuildZipFiles</mainClass>
                  <arguments>
                    <argument>${basedir}/target/classes</argument>
                  </arguments>
              </configuration>
            </execution>
           
           
             <!--generate meta data -->
             <execution>
               <id>generate-metadata</id>
               <phase>prepare-package</phase>
              <goals>
                <goal>java</goal>
              </goals>
              <configuration>
                  <includeProjectDependencies>false</includeProjectDependencies>
                  <includePluginDependencies>true</includePluginDependencies>
                  <executableDependency>
                    <groupId>AppDev</groupId>
                    <artifactId>configs-helper</artifactId>
                  </executableDependency>
                  <mainClass>com.riskmetrics.appdev.configs.tools.misc.WriteMimeTypeMetadata</mainClass>
                  <arguments>
                    <argument>${basedir}/target/classes/Configs</argument>
                    <argument>.*\.xml$|||text/xml|||Text File</argument>
                    <argument>.*\.xsl$|||text/xml|||Text File</argument>
                    <argument>.*\.rml$|||text/xml|||Text File</argument>
                    <argument>.*\.zip$|||application/octet-stream|||Binary Data</argument>
                    <argument>.*\.gif$|||image/gif|||GIF image</argument>
                    <argument>.*\.css$|||text/css|||CSS Text File</argument>
                    <argument>.*\.rcp$|||text/x-rmg-pns-recipe+rcp|||Recipe</argument>
                    <argument>.*\.search-folder$|||x-rmd-application/search-folder|||Search Folder</argument>
                    <argument>.*implicitFilter_.*|||x-rmd-filtergroup/filter-group|||Filter Group</argument>
                  </arguments>
              </configuration>
            </execution>
          </executions>
          <dependencies>
            <dependency>
              <groupId>AppDev</groupId>
              <artifactId>configs-helper</artifactId>
              <version>1.0-SNAPSHOT</version>
              <type>jar</type>
            </dependency>
        </dependencies>
       </plugin>
      
       <!-- copy config XML files to META-INF/config and replace $VERSION to the current pom version-->
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
              <id>copy-product-xml</id>
              <phase>process-sources</phase>
              <goals><goal>run</goal></goals>
              <configuration>
                  <tasks>
                     <copy todir="${basedir}/target/classes/META-INF/config">
                        <fileset dir="${basedir}/target/transformProducts">
                          <include name="**/*.xml"/>
                        </fileset>
                        <filterset>
                            <!-- replace CONFIG_VERSION to current version-->
                            <filter token="CONFIG_VERSION" value="${pom.name}-${project.version}"/>
                            <filter token="APP_VERSION" value=""/>
                        </filterset>
                      </copy>
                  </tasks>
              </configuration>
            </execution>
        </executions>
      </plugin>
   </plugins>
  </build>
   
  <properties>
    <buildGroup>bbConfigs</buildGroup>
    <buildName>common</buildName>
    <deployable>true</deployable>
   </properties>
</project>   

猜你喜欢

转载自dearls.iteye.com/blog/2281643
今日推荐