2010-08-26 72 views
3

我有一個由幾個模塊組成的Maven項目。我有一個POM文件用於調用所有相關模塊的構建。我想要做的是在所有子模塊的包生命週期完成後,將一堆文件複製到一個位置並壓縮一次。Maven多個模塊 - 後包裝步驟

我查看了antrun,但看不到如何讓它運行一次。目前它在每個模塊的包裝階段運行。這是我的父POM文件(簡體)

<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</groupId> 
<artifactId>parent</artifactId> 
<name>project</name> 
<version>1.0</version> 
<packaging>pom</packaging> 
<modules> 
    <module>../module1</module> 
    <module>../module2</module> 
</modules> 
<dependencies> 
    ... 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <configuration> 
         <tasks> 
          <mkdir dir="product" /> 
          <copy todir="product"> 
           <fileset dir="../module1/doc/release"> 
            <include name="*.pdf" /> 
           </fileset> 
           <fileset dir="../module2/doc/release"> 
            <include name="*.pdf" /> 
           </fileset> 
           <fileset dir="../module1/target"> 
            <include name="*.war" /> 
           </fileset> 
           <fileset dir="../module2/target"> 
            <include name="*.war" /> 
           </fileset> 
          </copy> 
          <copy file="app.properties" todir="cesium" /> 

          <zip basedir="product" destfile="dist.zip"></zip> 

         </tasks> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

<properties> 
    ... 
</properties> 

希望很清楚我想要做的事。我只想在包生命週期之後發生antrun任務,並且只發生一次,而不是每個模塊。

我知道我可能沒有以正確的方式接近這一步,但我不清楚如何用Maven解決這個問題。任何想法讚賞。

+0

嘿,既然mohommad shamsi給了你一個很好的答案,請確保你將他的答案標記爲已接受的答案。 – deterb 2010-09-06 20:14:50

回答

2
+0

非常好,謝謝。第一次嘗試*幾乎*做了我想要的,但我確信實驗將會到達那裏。感謝您的準確和快速響應! – 2010-08-26 15:49:32

+0

我最終得到它的工作,使用zip格式的程序集插件,以及fileSets和文件的組合。完美的作品,謝謝 – 2010-08-26 16:28:28

+0

;)不客氣。不要忘記接受答案並解決問題。 – mhshams 2010-08-26 16:48:13