views:

25

answers:

1

I have a Maven project that consists of several modules. I have a single POM file that I use to invoke the build of all dependent modules. What I want to do is to copy a bunch of files to a single location and zip them up once, after the package lifecycle of all the sub-modules has completed.

I've looked into antrun, but can't see how to make it run once. Currently it runs during the package phase of each module. Here's my parent POM file (simplified)

<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"&gt;
<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>

Hopefully it's clear what I'm trying to do. I just want the antrun task to happen after the package lifecycle, and only once, not for each module.

I understand that I might not be approaching this step the right way, but I'm unclear how best to aproach this with Maven. Any thoughts appreciated.

+2  A: 

try maven Assembly Plugin.

http://maven.apache.org/plugins/maven-assembly-plugin/

http://maven.apache.org/plugins/maven-assembly-plugin/examples/index.html

mohammad shamsi
Excellent, thanks. First attempt *almost* did what I wanted, but I'm sure experimentation will get there. Thanks for an accurate and fast response!
Mick Sear
I ended up getting it working, using the assembly plugin with a format of zip, and a combination of fileSets and files. Works perfectly, thanks
Mick Sear
;) you are welcome. don't forget to accept the answer and close the question.
mohammad shamsi